Update app.py
Browse files
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 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
#
|
107 |
-
|
|
|
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;
|