Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,24 +76,36 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
76 |
except Exception as e:
|
77 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
def process_financial_data(ticker):
|
|
|
|
|
|
|
|
|
80 |
try:
|
81 |
stock = yf.Ticker(ticker)
|
82 |
real_time_price = stock.history(period="1d") # ์ค์๊ฐ ์ฃผ์ ๊ฐ๊ฒฉ
|
83 |
-
stock_info = stock.info # ์ฃผ์ ์ ๋ณด
|
84 |
-
financial_data = stock.history(period="max") # ์ฃผ์ ๋ฐ์ดํฐ ๋ค์ด๋ก๋ ๋ฐ ๋ถ์
|
85 |
financials = stock.financials # ์ฌ๋ฌด์ ํ ๋ค์ด๋ก๋ ๋ฐ ๋ถ์
|
86 |
-
news_links = stock.news # ์ต์ ๋ด์ค ์กฐํ
|
87 |
-
|
88 |
return f"""**์ค์๊ฐ ์ฃผ์ ๊ฐ๊ฒฉ**: {real_time_price.tail(1)}
|
89 |
-
**๊ธฐ๋ณธ ์ฃผ์ ์ ๋ณด**: {stock_info.get('longName', '์ ๋ณด ์์')} ({stock_info.get('sector', '์ ๋ณด ์์')})
|
90 |
-
**์ฌ๋ฌด ๋ฐ์ดํฐ (์ต๊ทผ 5์ผ)**: {financial_data.tail(5)}
|
91 |
**์ฌ๋ฌด์ ํ**: {financials.head()}
|
92 |
-
**์ต์ ๋ด์ค ๋งํฌ**: {', '.join([news['title'] + ": " + news['link'] for news in news_links[:3]])}
|
93 |
"""
|
94 |
except Exception as e:
|
95 |
-
return f"Error: {str(e)} - ์ฃผ์
|
96 |
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
mychatbot = gr.Chatbot(
|
|
|
76 |
except Exception as e:
|
77 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
78 |
|
79 |
+
def validate_ticker(ticker):
|
80 |
+
stock = yf.Ticker(ticker)
|
81 |
+
# Yahoo Finance์์ ๊ธฐ๋ณธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ ํ์ธํฉ๋๋ค.
|
82 |
+
try:
|
83 |
+
info = stock.info
|
84 |
+
if not info:
|
85 |
+
raise ValueError("์ ํจํ์ง ์์ ํฐ์ปค์
๋๋ค.")
|
86 |
+
except Exception as e:
|
87 |
+
return False, str(e)
|
88 |
+
return True, "ํฐ์ปค ์ ํจ์ฑ ๊ฒ์ฆ ์ฑ๊ณต."
|
89 |
+
|
90 |
def process_financial_data(ticker):
|
91 |
+
valid, message = validate_ticker(ticker)
|
92 |
+
if not valid:
|
93 |
+
return f"Error: {message} - ์ฃผ์ ํฐ์ปค '{ticker}'๋ฅผ ํ์ธํ์ธ์."
|
94 |
+
|
95 |
try:
|
96 |
stock = yf.Ticker(ticker)
|
97 |
real_time_price = stock.history(period="1d") # ์ค์๊ฐ ์ฃผ์ ๊ฐ๊ฒฉ
|
|
|
|
|
98 |
financials = stock.financials # ์ฌ๋ฌด์ ํ ๋ค์ด๋ก๋ ๋ฐ ๋ถ์
|
|
|
|
|
99 |
return f"""**์ค์๊ฐ ์ฃผ์ ๊ฐ๊ฒฉ**: {real_time_price.tail(1)}
|
|
|
|
|
100 |
**์ฌ๋ฌด์ ํ**: {financials.head()}
|
|
|
101 |
"""
|
102 |
except Exception as e:
|
103 |
+
return f"Error: {str(e)} - ์ฃผ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค."
|
104 |
|
105 |
+
# ์์ ์ฌ์ฉ
|
106 |
+
ticker = "AAPL" # ์ฌ์ฉ์ ์
๋ ฅ ํฐ์ปค
|
107 |
+
result = process_financial_data(ticker)
|
108 |
+
print(result)
|
109 |
|
110 |
|
111 |
mychatbot = gr.Chatbot(
|