Abhaykoul commited on
Commit
d5f4461
1 Parent(s): ed4d24a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import time
4
+
5
+ # Create a session for reusing connections
6
+ session = requests.Session()
7
+
8
+ # Function to interact with the AI
9
+ def chat_with_ai(message):
10
+ api_url = "https://free-ai-api.devastation-war.repl.co/chat"
11
+ payload = {"message": message}
12
+
13
+ try:
14
+ with session.post(api_url, json=payload) as response:
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):
24
+ url = "https://test.devastation-war.repl.co/search"
25
+ payload = {"query": query}
26
+ response = requests.post(url, json=payload)
27
+
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():
35
+ query = st.text_input("Enter your research query: ")
36
+ if query:
37
+ # Perform web search
38
+ search_results = web_search(query)
39
+ # Pass the search results to the AI for generating a report
40
+ report = chat_with_ai(search_results)
41
+ # Display the report
42
+ st.write(report)
43
+
44
+ if __name__ == "__main__":
45
+ main()