Abhaykoul commited on
Commit
64375ed
β€’
1 Parent(s): 95af422

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -14,7 +14,7 @@ def chat_with_ai(message):
14
  if response.status_code == 200:
15
  return response.json().get('response') # Access 'response' key
16
  else:
17
- return {"error": "Failed to get a response from the AI API."}
18
  except requests.RequestException as e:
19
  return {"error": f"Error: {e}"}
20
 
@@ -31,23 +31,26 @@ def web_search(query):
31
 
32
  # Main function
33
  def main():
34
- st.title("HelpingAI Research Assistant")
35
-
36
- query = st.text_input("Enter your research query: ")
37
-
38
- if st.button("Generate Report"):
 
39
  if query:
40
- # Perform web search
41
- search_results = web_search(query)
 
42
 
43
  # Pass the search results to the AI for generating a report
44
- prompt = f"Generate a research report based on the following text: {search_results}, also provide source links at bottom also if search_results are not enough to generate report so answer users question from search_results"
45
- report = chat_with_ai(prompt)
 
46
 
47
  # Display the report
48
  st.write(report)
49
  else:
50
- st.write("Please enter a research query.")
51
 
52
  if __name__ == "__main__":
53
  main()
 
14
  if response.status_code == 200:
15
  return response.json().get('response') # Access 'response' key
16
  else:
17
+ return {"error": "Failed to get a response from the AI API. 😞"}
18
  except requests.RequestException as e:
19
  return {"error": f"Error: {e}"}
20
 
 
31
 
32
  # Main function
33
  def main():
34
+ st.title("πŸ” HelpingAI Research Assistant")
35
+ st.sidebar.header("πŸ› οΈ Settings")
36
+ query = st.sidebar.text_input("πŸ”Ž Enter your research query: ")
37
+ generate_report = st.sidebar.button("πŸ“ Generate Report")
38
+
39
+ if generate_report:
40
  if query:
41
+ with st.spinner('πŸ”„ Searching...'):
42
+ # Perform web search
43
+ search_results = web_search(query)
44
 
45
  # Pass the search results to the AI for generating a report
46
+ prompt = f"Generate a research report based on the following information: {search_results}. If the search results are insufficient, answer the user's question using the information available."
47
+ with st.spinner('πŸ”„ Generating report...'):
48
+ report = chat_with_ai(prompt)
49
 
50
  # Display the report
51
  st.write(report)
52
  else:
53
+ st.sidebar.error("❗ Please enter a research query.")
54
 
55
  if __name__ == "__main__":
56
  main()