Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,16 +66,33 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
66 |
formatted_prompt = format_prompt(prompt, history)
|
67 |
output_accumulated = ""
|
68 |
try:
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
output_accumulated
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
except Exception as e:
|
77 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
mychatbot = gr.Chatbot(
|
80 |
avatar_images=["./user.png", "./botm.png"],
|
81 |
bubble_full_width=False,
|
|
|
66 |
formatted_prompt = format_prompt(prompt, history)
|
67 |
output_accumulated = ""
|
68 |
try:
|
69 |
+
# ํฐ์ปค ํ์ธ ๋ฐ ๋ฐ์ดํฐ ์์ง
|
70 |
+
stock_info = get_stock_info(prompt) # ์ข
๋ชฉ๋ช
์ ํ ๋๋ก ํฐ์ปค ์ ๋ณด์ ๊ธฐ์
์ค๋ช
์ ๊ฐ์ ธ์ต๋๋ค.
|
71 |
+
if stock_info['ticker']:
|
72 |
+
response_msg = f"{stock_info['name']}์(๋) {stock_info['description']} ์ฃผ๋ ฅ์ผ๋ก ์์ฐํ๋ ๊ธฐ์
์
๋๋ค. {stock_info['name']}์ ํฐ์ปค๋ {stock_info['ticker']}์
๋๋ค. ์ํ์๋ ์ข
๋ชฉ์ด ๋ง๋๊ฐ์?"
|
73 |
+
output_accumulated += response_msg
|
74 |
+
yield output_accumulated
|
75 |
+
# ์ถ๊ฐ์ ์ธ ๋ถ์ ์์ฒญ์ด ์๋ค๋ฉด, yfinance๋ก ๋ฐ์ดํฐ ์์ง ๋ฐ ๋ถ์
|
76 |
+
stock_data = get_stock_data(stock_info['ticker']) # ํฐ์ปค๋ฅผ ์ด์ฉํด ์ฃผ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
|
77 |
+
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=min(max_new_tokens, available_tokens),
|
78 |
+
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
79 |
+
for response in stream:
|
80 |
+
output_part = response['generated_text'] if 'generated_text' in response else str(response)
|
81 |
+
output_accumulated += output_part
|
82 |
+
yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}\nStock Data: {stock_data}"
|
83 |
+
else:
|
84 |
+
yield "์
๋ ฅํ์ ์ข
๋ชฉ๋ช
์ ํ์ธํ ์ ์์ต๋๋ค. ์ ํํ ์ข
๋ชฉ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์."
|
85 |
except Exception as e:
|
86 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
87 |
|
88 |
+
# ์ข
๋ชฉ๋ช
์ ํ ๋๋ก ํฐ์ปค์ ๊ธฐ์
์ ๋ณด๋ฅผ ์ ๊ณตํ๋ ํจ์
|
89 |
+
def get_stock_info(name):
|
90 |
+
if name.lower() == "apple":
|
91 |
+
return {'ticker': 'AAPL', 'name': '์ ํ', 'description': '์์ดํฐ์'}
|
92 |
+
# ์ถ๊ฐ์ ์ธ ์ข
๋ชฉ์ ๋ํ ์ ๋ณด๋ฅผ ์ด๊ณณ์ ๊ตฌํํ ์ ์์ต๋๋ค.
|
93 |
+
return {'ticker': None, 'name': name, 'description': ''}
|
94 |
+
|
95 |
+
|
96 |
mychatbot = gr.Chatbot(
|
97 |
avatar_images=["./user.png", "./botm.png"],
|
98 |
bubble_full_width=False,
|