Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,29 @@ system_instruction = """
|
|
21 |
# ๋์ ํ ํฐ ์ฌ์ฉ๋์ ์ถ์ ํ๋ ์ ์ญ ๋ณ์
|
22 |
total_tokens_used = 0
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def format_prompt(message, history):
|
25 |
prompt = "<s>[SYSTEM] {} [/SYSTEM]".format(system_instruction)
|
26 |
for user_prompt, bot_response in history:
|
@@ -50,38 +73,46 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
50 |
except Exception as e:
|
51 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
}
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
demo
|
78 |
-
fn=generate,
|
79 |
-
chatbot=mychatbot,
|
80 |
-
title="๊ธ๋ก๋ฒ ์์ฐ(์ฃผ์,์ง์,์ํ,๊ฐ์์์ฐ,์ธํ ๋ฑ) ๋ถ์ LLM: BloombAI",
|
81 |
-
retry_btn=None,
|
82 |
-
undo_btn=None,
|
83 |
-
css=css,
|
84 |
-
examples=examples
|
85 |
-
)
|
86 |
|
87 |
-
|
|
|
|
21 |
# ๋์ ํ ํฐ ์ฌ์ฉ๋์ ์ถ์ ํ๋ ์ ์ญ ๋ณ์
|
22 |
total_tokens_used = 0
|
23 |
|
24 |
+
|
25 |
+
def fetch_ticker_info(ticker):
|
26 |
+
stock = yf.Ticker(ticker)
|
27 |
+
try:
|
28 |
+
info = stock.info
|
29 |
+
# ์ ํ์ ์ผ๋ก ์ถ๋ ฅํ ์ ๋ณด๋ฅผ ์ ์ ํฉ๋๋ค.
|
30 |
+
result = {
|
31 |
+
"์ข
๋ชฉ๋ช
": info.get("longName"),
|
32 |
+
"์์ฅ ๊ฐ๊ฒฉ": info.get("regularMarketPrice"),
|
33 |
+
"์ ์ผ ์ข
๊ฐ": info.get("previousClose"),
|
34 |
+
"์๊ฐ": info.get("open"),
|
35 |
+
"๊ณ ๊ฐ": info.get("dayHigh"),
|
36 |
+
"์ ๊ฐ": info.get("dayLow"),
|
37 |
+
"52์ฃผ ์ต๊ณ ": info.get("fiftyTwoWeekHigh"),
|
38 |
+
"52์ฃผ ์ต์ ": info.get("fiftyTwoWeekLow"),
|
39 |
+
"์๊ฐ์ด์ก": info.get("marketCap"),
|
40 |
+
"๋ฐฐ๋น ์์ต๋ฅ ": info.get("dividendYield"),
|
41 |
+
"์ฃผ์ ์": info.get("sharesOutstanding")
|
42 |
+
}
|
43 |
+
return "\n".join([f"{key}: {value}" for key, value in result.items() if value is not None])
|
44 |
+
except ValueError:
|
45 |
+
return "์ ํจํ์ง ์์ ํฐ์ปค์
๋๋ค. ๋ค์ ์
๋ ฅํด์ฃผ์ธ์."
|
46 |
+
|
47 |
def format_prompt(message, history):
|
48 |
prompt = "<s>[SYSTEM] {} [/SYSTEM]".format(system_instruction)
|
49 |
for user_prompt, bot_response in history:
|
|
|
73 |
except Exception as e:
|
74 |
yield f"Error: {str(e)}\nTotal tokens used: {total_tokens_used}"
|
75 |
|
76 |
+
# ๊ธฐ์กด์ ์ฑํ
์ธํฐํ์ด์ค์ ํฐ์ปค ์
๋ ฅ ๊ธฐ๋ฅ์ ํตํฉ
|
77 |
+
def setup_interface():
|
78 |
+
with gr.Blocks() as demo:
|
79 |
+
gr.Markdown("### ๊ธ๋ก๋ฒ ์์ฐ(์ฃผ์,์ง์,์ํ,๊ฐ์์์ฐ,์ธํ ๋ฑ) ๋ถ์ LLM: BloombAI")
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
ticker_input = gr.Textbox(label="ํฐ์ปค ์
๋ ฅ", placeholder="์: AAPL", elem_id="ticker_input")
|
83 |
+
submit_button = gr.Button("์กฐํ", elem_id="submit_button")
|
84 |
+
|
85 |
+
chatbot = gr.Chatbot(
|
86 |
+
avatar_images=["./user.png", "./botm.png"],
|
87 |
+
bubble_full_width=False,
|
88 |
+
show_label=False,
|
89 |
+
show_copy_button=True,
|
90 |
+
likeable=True,
|
91 |
+
elem_id="chatbot_area"
|
92 |
+
)
|
93 |
+
|
94 |
+
# ๊ฒฐ๊ณผ๋ฅผ ์ฑํ
์ธํฐํ์ด์ค์ ์ถ๋ ฅํ๋๋ก ์ค์
|
95 |
+
submit_button.click(
|
96 |
+
fn=lambda x: f"ํฐ์ปค '{x}'์ ์ ๋ณด ์กฐํ ๊ฒฐ๊ณผ:\n\n{fetch_ticker_info(x)}",
|
97 |
+
inputs=ticker_input,
|
98 |
+
outputs=chatbot
|
99 |
+
)
|
100 |
+
|
101 |
+
gr.Markdown("### ์ฑํ
")
|
102 |
+
examples = [
|
103 |
+
["๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ.", []],
|
104 |
+
["๋ถ์ ๊ฒฐ๊ณผ ๋ณด๊ณ ์ ๋ค์ ์ถ๋ ฅํ ๊ฒ", []],
|
105 |
+
["์ถ์ฒ ์ข
๋ชฉ ์๋ ค์ค", []],
|
106 |
+
["๊ทธ ์ข
๋ชฉ ํฌ์ ์ ๋ง ์์ธกํด", []]
|
107 |
+
]
|
108 |
+
chatbot.update(
|
109 |
+
fn=generate,
|
110 |
+
inputs=[gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", elem_id="message_input")],
|
111 |
+
outputs=chatbot,
|
112 |
+
examples=examples
|
113 |
+
)
|
114 |
|
115 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
app = setup_interface()
|
118 |
+
app.launch()
|