James MacQuillan commited on
Commit
4f30126
Β·
1 Parent(s): 7561312
Files changed (1) hide show
  1. app.py +47 -31
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
- # Accumulate streamed content from the initial request
 
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 assuming any specific dates use 'this year', 'this month', etc. make sure that you do generate a good search based on the query, for example if the user asks 'build a DFCF model for Apple', search up something like 'Apple DFCF model', and if they ask for something like a market cap, just search up what is Apple's current market cap. make sure that you provide a good google search all of the time, for example if they ask for the price of pulsar helium stock just search for it"}],
100
  max_tokens=400,
101
  stream=True
102
  )
103
- yield 'Generating search term based on your input πŸ”'
104
- # Accumulate content from the streamed response
105
- streamed_search_query = ""
106
  for chunk in stream_search:
107
  content = chunk.choices[0].delta.content or ''
108
- streamed_search_query += content
109
 
110
-
111
  yield 'Searching the web for relevant information 🌐'
112
- # Perform the web search based on the accumulated query
113
- search_results = search(streamed_search_query)
 
114
  search_results_str = json.dumps(search_results)
115
 
116
- # Create the response request with HuggingFace using search results
117
  response = client.chat_completion(
118
  model="Qwen/Qwen2.5-72B-Instruct",
119
- messages=[{"role": "user", "content": f"YOU ARE AN INVESTMENT CHATBOT . Answer the user's request '{user_input}' using the following information: {search_results} and the chat history {history}. Provide a concise, direct answer in no more than 2-3 sentences, with appropriate emojis HOWEVER DONT OVERUSE AND ONLY USE EMOJIS RELATED TO STOCKS. YOU MUST GIVE THE NUMERICAL DATA VALUES TO THE USER WHEN THEY ASK YOU SOMETHING TO BACK UP WHAT YOU ARE SAYING! . If the user asks for a smart sheet, generate up to 3000 tokens analyzing all trends and patterns as though you are a stock analyst, look for every pattern and form conclusions. IF YOU ARE ASKED TO BUILD MODELS OR LIST STOCKS, USE THE SEARCH DATA TO HELP YOU BUILD THEM AND MAKE SURE YOU ACTUALLY GIVE THE VALUES AND WHAT THE ARTICLE SAYS RATHER THAN JUST SAYING THAT IT IS AVAILABLE FROM THE WEBSITE. unless the user asks for a smart sheet. keep responses short, quick and logical, using the data provided. AT THE END OF EACH RESPONSE ESPECIALLY SAY HOW THIS IS NOT FINANCIAL ADVICE AND QUANTINEURON.COM IS NOT RESPONSIBLE FOR ANYTHING THAT GOES WRONG BECAUSE OF WHAT YOU SAY, AND THAT BY USING YOU, YOU AGREE TO OUR DISCLAIMER STATEMENT, TERMS OF SERVICE, TERMS AND CONSITIONS AND DATA COLLECTION AND PRIVACY POLICY. "}],
120
  max_tokens=3000,
121
  stream=True
122
  )
 
123
  yield "Analyzing the search results and crafting a response πŸ“Š"
124
- # Accumulate the final response and stream it
 
125
  final_response = ""
126
  for chunk in response:
127
  content = chunk.choices[0].delta.content or ''
128
  final_response += content
129
- yield final_response # Yield the accumulated response for real-time streaming
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 techncial indicators for nvidia"],
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
- ["analyse the technical indicators for apple"],
145
- ["build an intrinsic value model for apple"],
146
  ["Make a table of Apple's stock price for the last 3 days"],
147
- ['what is Apples PE ratio and how does it compare top other companies in consumer electronics'],
148
- ['how did salesforce do on its last earnings?'],
149
- ['what is the average analyst price target for Nvidia'],
150
- ['whats the outlook for the stock market in 2025'],
151
- ['when does Nvidia next report earnings'],
152
- ['what are the latest products from apple'],
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
- chat_interface = gr.ChatInterface(
172
- theme=theme,
173
- fn=process_query,
174
- chatbot=chatbot,
175
- examples=examples,
176
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
- chat_interface.launch()
 
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()