Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -88,10 +88,46 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
88 |
output_accumulated += output_part
|
89 |
yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}\nStock Data: {stock_data}"
|
90 |
else:
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
except Exception as e:
|
93 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# μ’
λͺ©λͺ
μ ν λλ‘ ν°μ»€μ κΈ°μ
μ 보λ₯Ό μ 곡νλ ν¨μ
|
96 |
def get_stock_info(name):
|
97 |
stock_info = {
|
|
|
88 |
output_accumulated += output_part
|
89 |
yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}\nStock Data: {stock_data}"
|
90 |
else:
|
91 |
+
# μ
λ ₯μ΄ ν°μ»€μΈ κ²½μ° μ²λ¦¬
|
92 |
+
ticker = prompt.upper()
|
93 |
+
if ticker in ['AAPL', 'MSFT', 'AMZN', 'GOOGL', 'TSLA']:
|
94 |
+
stock_info = get_stock_info_by_ticker(ticker)
|
95 |
+
response_msg = f"{stock_info['name']}μ(λ) {stock_info['description']} μ£Όλ ₯μΌλ‘ μμ°νλ κΈ°μ
μ
λλ€. {stock_info['name']}μ ν°μ»€λ {stock_info['ticker']}μ
λλ€. μνμλ μ’
λͺ©μ΄ λ§λκ°μ?"
|
96 |
+
output_accumulated += response_msg
|
97 |
+
yield output_accumulated
|
98 |
+
|
99 |
+
# μΆκ°μ μΈ λΆμ μμ²μ΄ μλ€λ©΄, yfinanceλ‘ λ°μ΄ν° μμ§ λ° λΆμ
|
100 |
+
stock_data = get_stock_data(stock_info['ticker']) # ν°μ»€λ₯Ό μ΄μ©ν΄ μ£Όμ λ°μ΄ν°λ₯Ό κ°μ Έμ΅λλ€.
|
101 |
+
stream = client.text_generation(
|
102 |
+
formatted_prompt,
|
103 |
+
temperature=temperature,
|
104 |
+
max_new_tokens=min(max_new_tokens, available_tokens),
|
105 |
+
top_p=top_p,
|
106 |
+
repetition_penalty=repetition_penalty,
|
107 |
+
do_sample=True,
|
108 |
+
seed=42,
|
109 |
+
stream=True
|
110 |
+
)
|
111 |
+
for response in stream:
|
112 |
+
output_part = response['generated_text'] if 'generated_text' in response else str(response)
|
113 |
+
output_accumulated += output_part
|
114 |
+
yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}\nStock Data: {stock_data}"
|
115 |
+
else:
|
116 |
+
yield f"μ
λ ₯νμ '{prompt}'μ(λ) μ§μλλ μ’
λͺ©λͺ
λλ ν°μ»€κ° μλλλ€. νμ¬ μ§μλλ μ’
λͺ©μ μ ν(AAPL), λ§μ΄ν¬λ‘μννΈ(MSFT), μλ§μ‘΄(AMZN), μνλ²³(GOOGL), ν
μ¬λΌ(TSLA) λ±μ
λλ€. μ νν μ’
λͺ©λͺ
λλ ν°μ»€λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
117 |
except Exception as e:
|
118 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
119 |
|
120 |
+
# ν°μ»€λ₯Ό ν λλ‘ μ’
λͺ© μ 보λ₯Ό μ 곡νλ ν¨μ
|
121 |
+
def get_stock_info_by_ticker(ticker):
|
122 |
+
stock_info = {
|
123 |
+
"AAPL": {'ticker': 'AAPL', 'name': 'μ ν', 'description': 'μμ΄ν°μ'},
|
124 |
+
"MSFT": {'ticker': 'MSFT', 'name': 'λ§μ΄ν¬λ‘μννΈ', 'description': 'μλμ° μ΄μ체μ μ μ€νΌμ€ μννΈμ¨μ΄λ₯Ό'},
|
125 |
+
"AMZN": {'ticker': 'AMZN', 'name': 'μλ§μ‘΄', 'description': 'μ μμκ±°λ λ° ν΄λΌμ°λ μλΉμ€λ₯Ό'},
|
126 |
+
"GOOGL": {'ticker': 'GOOGL', 'name': 'μνλ²³', 'description': 'κ²μ μμ§ λ° μ¨λΌμΈ κ΄κ³ λ₯Ό'},
|
127 |
+
"TSLA": {'ticker': 'TSLA', 'name': 'ν
μ¬λΌ', 'description': 'μ κΈ°μλμ°¨μ μλμ§ μ μ₯μ₯μΉλ₯Ό'},
|
128 |
+
}
|
129 |
+
return stock_info.get(ticker, {'ticker': None, 'name': None, 'description': ''})
|
130 |
+
|
131 |
# μ’
λͺ©λͺ
μ ν λλ‘ ν°μ»€μ κΈ°μ
μ 보λ₯Ό μ 곡νλ ν¨μ
|
132 |
def get_stock_info(name):
|
133 |
stock_info = {
|