seawolf2357 commited on
Commit
71c773c
ยท
verified ยท
1 Parent(s): 11bce52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
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"""**์‹ค์‹œ๊ฐ„ ์ฃผ์‹ ๊ฐ€๊ฒฉ**: {real_time_price.tail(1)}
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,