Spaces:
Sleeping
Sleeping
James MacQuillan
commited on
Commit
Β·
4f30126
1
Parent(s):
7561312
push
Browse files
app.py
CHANGED
@@ -89,44 +89,47 @@ def search(query):
|
|
89 |
print(f"Google search failed: {e}")
|
90 |
|
91 |
return all_results
|
92 |
-
|
93 |
def process_query(user_input, history):
|
94 |
-
|
95 |
yield 'Preparing your request π οΈ'
|
96 |
-
|
|
|
97 |
stream_search = client.chat_completion(
|
98 |
model="Qwen/Qwen2.5-72B-Instruct",
|
99 |
-
messages=[{"role": "user", "content": f"Based on this chat history {history} and the user's request '{user_input}', suggest a Google search term in a single line without
|
100 |
max_tokens=400,
|
101 |
stream=True
|
102 |
)
|
103 |
-
|
104 |
-
#
|
105 |
-
|
106 |
for chunk in stream_search:
|
107 |
content = chunk.choices[0].delta.content or ''
|
108 |
-
|
109 |
|
110 |
-
|
111 |
yield 'Searching the web for relevant information π'
|
112 |
-
|
113 |
-
|
|
|
114 |
search_results_str = json.dumps(search_results)
|
115 |
|
116 |
-
#
|
117 |
response = client.chat_completion(
|
118 |
model="Qwen/Qwen2.5-72B-Instruct",
|
119 |
-
messages=[{"role": "user", "content": f"
|
120 |
max_tokens=3000,
|
121 |
stream=True
|
122 |
)
|
|
|
123 |
yield "Analyzing the search results and crafting a response π"
|
124 |
-
|
|
|
125 |
final_response = ""
|
126 |
for chunk in response:
|
127 |
content = chunk.choices[0].delta.content or ''
|
128 |
final_response += content
|
129 |
-
yield final_response
|
130 |
|
131 |
theme = gr.themes.Citrus(
|
132 |
primary_hue="blue",
|
@@ -137,19 +140,19 @@ examples = [
|
|
137 |
["whats the trending social sentiment like for Nvidia"],
|
138 |
["What's the latest news on Cisco Systems stock"],
|
139 |
["Analyze technical indicators for Adobe, are they presenting buy or sell signals"],
|
140 |
-
["Write me a smart sheet on the trending social sentiment and
|
141 |
["What are the best stocks to buy this month"],
|
142 |
["What companies report earnings this week"],
|
143 |
["What's Apple's current market cap"],
|
144 |
-
["
|
145 |
-
["
|
146 |
["Make a table of Apple's stock price for the last 3 days"],
|
147 |
-
[
|
148 |
-
[
|
149 |
-
[
|
150 |
-
[
|
151 |
-
[
|
152 |
-
[
|
153 |
["What is Tesla's current price-to-earnings ratio and how does it compare to other car manufacturers?"],
|
154 |
["List the top 5 performing stocks in the S&P 500 this month"],
|
155 |
["What is the dividend yield for Coca-Cola?"],
|
@@ -168,11 +171,24 @@ chatbot = gr.Chatbot(
|
|
168 |
height=700
|
169 |
)
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
|
|
|
89 |
print(f"Google search failed: {e}")
|
90 |
|
91 |
return all_results
|
92 |
+
|
93 |
def process_query(user_input, history):
|
|
|
94 |
yield 'Preparing your request π οΈ'
|
95 |
+
|
96 |
+
# Step 1: Generate a search term based on the user query
|
97 |
stream_search = client.chat_completion(
|
98 |
model="Qwen/Qwen2.5-72B-Instruct",
|
99 |
+
messages=[{"role": "user", "content": f"Based on this chat history {history} and the user's request '{user_input}', suggest a Google search term in a single line without specific dates; use 'this year', 'this month', etc. INCLUDE NOTHING IN YOUR RESPONSE EXCEPT THE RELEVANT SEARCH RESULT. EXAMPLE: USER: WHAT IS THE CURRENT PRICE OF COCA COLA STOCK. YOUR RESPONSE: WHAT IS THE CURRENT PRICE OF COCA COLA STOCK"}],
|
100 |
max_tokens=400,
|
101 |
stream=True
|
102 |
)
|
103 |
+
|
104 |
+
# Collect the search term
|
105 |
+
search_query = ""
|
106 |
for chunk in stream_search:
|
107 |
content = chunk.choices[0].delta.content or ''
|
108 |
+
search_query += content
|
109 |
|
110 |
+
# Step 2: Perform the web search with the generated term
|
111 |
yield 'Searching the web for relevant information π'
|
112 |
+
search_results = search(search_query)
|
113 |
+
|
114 |
+
# Format results as a JSON string for model input
|
115 |
search_results_str = json.dumps(search_results)
|
116 |
|
117 |
+
# Step 3: Generate a response using the search results
|
118 |
response = client.chat_completion(
|
119 |
model="Qwen/Qwen2.5-72B-Instruct",
|
120 |
+
messages=[{"role": "user", "content": f"Using the search results: {search_results_str} and chat history {history}, answer the user's query '{user_input}' concisely, using numerical data if available. "}],
|
121 |
max_tokens=3000,
|
122 |
stream=True
|
123 |
)
|
124 |
+
|
125 |
yield "Analyzing the search results and crafting a response π"
|
126 |
+
|
127 |
+
# Stream final response
|
128 |
final_response = ""
|
129 |
for chunk in response:
|
130 |
content = chunk.choices[0].delta.content or ''
|
131 |
final_response += content
|
132 |
+
yield final_response
|
133 |
|
134 |
theme = gr.themes.Citrus(
|
135 |
primary_hue="blue",
|
|
|
140 |
["whats the trending social sentiment like for Nvidia"],
|
141 |
["What's the latest news on Cisco Systems stock"],
|
142 |
["Analyze technical indicators for Adobe, are they presenting buy or sell signals"],
|
143 |
+
["Write me a smart sheet on the trending social sentiment and technical indicators for Nvidia"],
|
144 |
["What are the best stocks to buy this month"],
|
145 |
["What companies report earnings this week"],
|
146 |
["What's Apple's current market cap"],
|
147 |
+
["Analyze the technical indicators for Apple"],
|
148 |
+
["Build an intrinsic value model for Apple"],
|
149 |
["Make a table of Apple's stock price for the last 3 days"],
|
150 |
+
["What is Apple's PE ratio and how does it compare to other companies in consumer electronics"],
|
151 |
+
["How did Salesforce perform in its last earnings?"],
|
152 |
+
["What is the average analyst price target for Nvidia"],
|
153 |
+
["What is the outlook for the stock market in 2025"],
|
154 |
+
["When does Nvidia next report earnings"],
|
155 |
+
["What are the latest products from Apple"],
|
156 |
["What is Tesla's current price-to-earnings ratio and how does it compare to other car manufacturers?"],
|
157 |
["List the top 5 performing stocks in the S&P 500 this month"],
|
158 |
["What is the dividend yield for Coca-Cola?"],
|
|
|
171 |
height=700
|
172 |
)
|
173 |
|
174 |
+
with gr.Blocks(theme=theme) as demo:
|
175 |
+
with gr.Column():
|
176 |
+
gr.Markdown("## IM.S - Building the Future of Investing")
|
177 |
+
|
178 |
+
with gr.Column(scale=3, min_width=600):
|
179 |
+
chat_interface = gr.ChatInterface(
|
180 |
+
fn=process_query,
|
181 |
+
chatbot=chatbot,
|
182 |
+
examples=examples
|
183 |
+
)
|
184 |
+
|
185 |
+
with gr.Column():
|
186 |
+
gr.Markdown('''
|
187 |
+
**Disclaimer**: The information provided by IM.S is for educational and informational purposes only and does not constitute financial, investment, or professional advice. By using this service, you acknowledge and agree that all decisions you make based on the information provided are made at your own risk. Neither IM.S nor quantineuron.com is liable for any financial losses or damages resulting from reliance on information provided by this chatbot.
|
188 |
+
|
189 |
+
By using IM.S, you agree to be bound by quantineuron.comβs [Terms of Service](https://quantineuron.com/disclaimer-statement/), [Terms and Conditions](https://quantineuron.com/terms-and-conditions/), [Data Protection and Privacy Policy](https://quantineuron.com/data-protection-and-privacy-policy/), [our discalimer statement](https://quantineuron.com/disclaimer-statement/) and this Disclaimer Statement. We recommend reviewing these documents carefully. Your continued use of this service confirms your acceptance of these terms and conditions, and it is your responsibility to stay informed of any updates or changes.
|
190 |
+
|
191 |
+
**Important Note**: Investing in financial markets carries risk, and it is possible to lose some or all of the invested capital. Always consider seeking advice from a qualified financial advisor.
|
192 |
+
''')
|
193 |
|
194 |
+
demo.launch()
|