Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ import gradio as gr
|
|
3 |
from transformers import GPT2Tokenizer
|
4 |
import yfinance as yf
|
5 |
import time
|
|
|
|
|
|
|
6 |
|
7 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
8 |
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
@@ -77,13 +80,15 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
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 |
|
@@ -94,12 +99,11 @@ def process_financial_data(ticker):
|
|
94 |
|
95 |
try:
|
96 |
stock = yf.Ticker(ticker)
|
97 |
-
real_time_price = stock.history(period="1d")
|
98 |
-
financials = stock.financials
|
99 |
-
return f"
|
100 |
-
**์ฌ๋ฌด์ ํ**: {financials.head()}
|
101 |
-
"""
|
102 |
except Exception as e:
|
|
|
103 |
return f"Error: {str(e)} - ์ฃผ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค."
|
104 |
|
105 |
# ์์ ์ฌ์ฉ
|
@@ -107,7 +111,6 @@ ticker = "AAPL" # ์ฌ์ฉ์ ์
๋ ฅ ํฐ์ปค
|
|
107 |
result = process_financial_data(ticker)
|
108 |
print(result)
|
109 |
|
110 |
-
|
111 |
mychatbot = gr.Chatbot(
|
112 |
avatar_images=["./user.png", "./botm.png"],
|
113 |
bubble_full_width=False,
|
|
|
3 |
from transformers import GPT2Tokenizer
|
4 |
import yfinance as yf
|
5 |
import time
|
6 |
+
import logging
|
7 |
+
|
8 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
9 |
|
10 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
11 |
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
|
|
80 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
81 |
|
82 |
def validate_ticker(ticker):
|
83 |
+
logging.debug(f"Validating ticker: {ticker}")
|
84 |
stock = yf.Ticker(ticker)
|
|
|
85 |
try:
|
86 |
info = stock.info
|
87 |
if not info:
|
88 |
raise ValueError("์ ํจํ์ง ์์ ํฐ์ปค์
๋๋ค.")
|
89 |
+
logging.debug(f"Ticker {ticker} is valid.")
|
90 |
except Exception as e:
|
91 |
+
logging.error(f"Failed to validate ticker {ticker}: {e}")
|
92 |
return False, str(e)
|
93 |
return True, "ํฐ์ปค ์ ํจ์ฑ ๊ฒ์ฆ ์ฑ๊ณต."
|
94 |
|
|
|
99 |
|
100 |
try:
|
101 |
stock = yf.Ticker(ticker)
|
102 |
+
real_time_price = stock.history(period="1d")
|
103 |
+
financials = stock.financials
|
104 |
+
return f"**์ค์๊ฐ ์ฃผ์ ๊ฐ๊ฒฉ**: {real_time_price.tail(1)}\n**์ฌ๋ฌด์ ํ**: {financials.head()}"
|
|
|
|
|
105 |
except Exception as e:
|
106 |
+
logging.error(f"Error processing financial data for {ticker}: {e}")
|
107 |
return f"Error: {str(e)} - ์ฃผ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค."
|
108 |
|
109 |
# ์์ ์ฌ์ฉ
|
|
|
111 |
result = process_financial_data(ticker)
|
112 |
print(result)
|
113 |
|
|
|
114 |
mychatbot = gr.Chatbot(
|
115 |
avatar_images=["./user.png", "./botm.png"],
|
116 |
bubble_full_width=False,
|