Abhaykoul commited on
Commit
aebe303
β€’
1 Parent(s): 4e15bfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -15,9 +15,9 @@ def chat_with_ai(message, user_input):
15
  if response.status_code == 200:
16
  return response.json().get('response') # Access 'response' key
17
  else:
18
- return {"error": "Failed to get a response from the AI API. 😞"}
19
  except requests.RequestException as e:
20
- return {"error": f"Error: {e}"}
21
 
22
  # Function to perform web search
23
  def web_search(query):
@@ -28,7 +28,7 @@ def web_search(query):
28
  if response.status_code == 200:
29
  return response.json()
30
  else:
31
- return {"error": f"Error: {response.status_code}"}
32
 
33
  # Main function
34
  def main():
@@ -65,12 +65,15 @@ def main():
65
  search_results = web_search(query)
66
 
67
  # Pass the search results to the AI for generating a report
68
- prompt = f"Generate a research report based on the following information: {search_results}. The user's query was: '{query}'. If the search results are insufficient, answer the user's question using the information available."
69
  with st.spinner('πŸ”„ Generating report...'):
70
  report = chat_with_ai(prompt, query)
71
 
72
  # Display the report
73
- st.write(report)
 
 
 
74
 
75
  # Update recent reports
76
  recent_reports.text(query)
 
15
  if response.status_code == 200:
16
  return response.json().get('response') # Access 'response' key
17
  else:
18
+ st.error("Failed to get a response from the AI API. 😞")
19
  except requests.RequestException as e:
20
+ st.error(f"Error: {e}")
21
 
22
  # Function to perform web search
23
  def web_search(query):
 
28
  if response.status_code == 200:
29
  return response.json()
30
  else:
31
+ st.error(f"Error: {response.status_code}")
32
 
33
  # Main function
34
  def main():
 
65
  search_results = web_search(query)
66
 
67
  # Pass the search results to the AI for generating a report
68
+ prompt = f"Generate a detailed research report based on the following information: {search_results}. The user's query was: '{query}'. Please include an overview, key findings, and any relevant details in the report. If the search results are insufficient, answer the user's question using the information available."
69
  with st.spinner('πŸ”„ Generating report...'):
70
  report = chat_with_ai(prompt, query)
71
 
72
  # Display the report
73
+ if isinstance(report, dict) and 'error' in report:
74
+ st.error(report['error'])
75
+ else:
76
+ st.write(report)
77
 
78
  # Update recent reports
79
  recent_reports.text(query)