seawolf2357 commited on
Commit
22de012
ยท
verified ยท
1 Parent(s): 1841879

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -6,7 +6,6 @@ import time
6
  import logging
7
  from datetime import datetime
8
 
9
-
10
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
11
 
12
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
@@ -64,7 +63,6 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
64
  input_tokens = len(tokenizer.encode(prompt))
65
  total_tokens_used += input_tokens
66
  available_tokens = 32768 - total_tokens_used
67
-
68
  if available_tokens <= 0:
69
  yield f"Error: ์ž…๋ ฅ์ด ์ตœ๋Œ€ ํ—ˆ์šฉ ํ† ํฐ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•ฉ๋‹ˆ๋‹ค. Total tokens used: {total_tokens_used}"
70
  return
@@ -78,11 +76,18 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
78
  output_part = response['generated_text'] if 'generated_text' in response else str(response)
79
  output_accumulated += output_part
80
 
81
- # ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ ๋ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
82
  if "ํ‹ฐ์ปค" in output_part:
83
- ticker = extract_ticker(output_part) # ํ‹ฐ์ปค ์ถ”์ถœํ•˜๋Š” ๋”๋ฏธ ํ•จ์ˆ˜, ์‹ค์ œ๋กœ๋Š” ํ‹ฐ์ปค๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋กœ์ง ํ•„์š”
84
- download_result = download_stock_data(ticker)
85
- output_accumulated += download_result
 
 
 
 
 
 
 
86
 
87
  yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}"
88
  except Exception as e:
@@ -99,12 +104,14 @@ def download_stock_data(ticker):
99
  else:
100
  return f"Success: {ticker} ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ ์„ฑ๊ณต."
101
  except Exception as e:
 
102
  return f"Error: ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. {str(e)}"
103
 
104
  def extract_ticker(output_part):
105
- # ์ด ํ•จ์ˆ˜๋Š” ์‚ฌ์šฉ์ž ์ถœ๋ ฅ์—์„œ ํ‹ฐ์ปค๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•จ
106
- # ์—ฌ๊ธฐ์„œ๋Š” ์˜ˆ์‹œ๋กœ 'AAPL'์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์„ค์ •
107
- return "AAPL"
 
108
 
109
  def validate_ticker(ticker):
110
  logging.debug(f"Validating ticker: {ticker}")
@@ -132,11 +139,6 @@ def process_financial_data(ticker):
132
  logging.error(f"Error processing financial data for {ticker}: {e}")
133
  return f"Error: {str(e)} - ์ฃผ์‹ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
134
 
135
- # ์˜ˆ์‹œ ์‚ฌ์šฉ
136
- ticker = "AAPL" # ์‚ฌ์šฉ์ž ์ž…๋ ฅ ํ‹ฐ์ปค
137
- result = process_financial_data(ticker)
138
- print(result)
139
-
140
  mychatbot = gr.Chatbot(
141
  avatar_images=["./user.png", "./botm.png"],
142
  bubble_full_width=False,
@@ -154,7 +156,7 @@ examples = [
154
 
155
  css = """
156
  h1 {
157
- font-size: 14px; /* ์ œ๋ชฉ ๊ธ€๊ผด ํฌ๊ธฐ๋ฅผ ์ž‘๊ฒŒ ์„ค์ • */
158
  }
159
  footer {
160
  visibility: hidden;
 
6
  import logging
7
  from datetime import datetime
8
 
 
9
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
10
 
11
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
 
63
  input_tokens = len(tokenizer.encode(prompt))
64
  total_tokens_used += input_tokens
65
  available_tokens = 32768 - total_tokens_used
 
66
  if available_tokens <= 0:
67
  yield f"Error: ์ž…๋ ฅ์ด ์ตœ๋Œ€ ํ—ˆ์šฉ ํ† ํฐ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•ฉ๋‹ˆ๋‹ค. Total tokens used: {total_tokens_used}"
68
  return
 
76
  output_part = response['generated_text'] if 'generated_text' in response else str(response)
77
  output_accumulated += output_part
78
 
79
+ # ํ‹ฐ์ปค ์ถ”์ถœ ๋ฐ ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ
80
  if "ํ‹ฐ์ปค" in output_part:
81
+ ticker = extract_ticker(output_part)
82
+ if ticker:
83
+ download_result = download_stock_data(ticker)
84
+ output_accumulated += download_result
85
+
86
+ # ํ‹ฐ์ปค ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐ ์žฌ๋ฌด ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ
87
+ financial_data = process_financial_data(ticker)
88
+ output_accumulated += financial_data
89
+ else:
90
+ output_accumulated += "Error: ํ‹ฐ์ปค๋ฅผ ์ถ”์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
91
 
92
  yield output_accumulated + f"\n\n---\nTotal tokens used: {total_tokens_used}"
93
  except Exception as e:
 
104
  else:
105
  return f"Success: {ticker} ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ ์„ฑ๊ณต."
106
  except Exception as e:
107
+ logging.error(f"Error downloading data for {ticker}: {e}")
108
  return f"Error: ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. {str(e)}"
109
 
110
  def extract_ticker(output_part):
111
+ # ์‚ฌ์šฉ์ž ์ถœ๋ ฅ์—์„œ ํ‹ฐ์ปค๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋กœ์ง ๊ตฌํ˜„
112
+ # ์˜ˆ์‹œ: 'AAPL' ์ถ”์ถœ
113
+ ticker = "AAPL" # ์‹ค์ œ ํ‹ฐ์ปค ์ถ”์ถœ ๋กœ์ง์œผ๋กœ ๋Œ€์ฒด ํ•„์š”
114
+ return ticker
115
 
116
  def validate_ticker(ticker):
117
  logging.debug(f"Validating ticker: {ticker}")
 
139
  logging.error(f"Error processing financial data for {ticker}: {e}")
140
  return f"Error: {str(e)} - ์ฃผ์‹ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
141
 
 
 
 
 
 
142
  mychatbot = gr.Chatbot(
143
  avatar_images=["./user.png", "./botm.png"],
144
  bubble_full_width=False,
 
156
 
157
  css = """
158
  h1 {
159
+ font-size: 14px;
160
  }
161
  footer {
162
  visibility: hidden;