Abhaykoul's picture
Create app.py
d5f4461
raw
history blame
No virus
1.37 kB
import streamlit as st
import requests
import time
# Create a session for reusing connections
session = requests.Session()
# Function to interact with the AI
def chat_with_ai(message):
api_url = "https://free-ai-api.devastation-war.repl.co/chat"
payload = {"message": message}
try:
with session.post(api_url, json=payload) as response:
if response.status_code == 200:
return response.json().get('response') # Access 'response' key
else:
return {"error": "Failed to get a response from the AI API."}
except requests.RequestException as e:
return {"error": f"Error: {e}"}
# Function to perform web search
def web_search(query):
url = "https://test.devastation-war.repl.co/search"
payload = {"query": query}
response = requests.post(url, json=payload)
if response.status_code == 200:
return response.json()
else:
return {"error": f"Error: {response.status_code}"}
# Main function
def main():
query = st.text_input("Enter your research query: ")
if query:
# Perform web search
search_results = web_search(query)
# Pass the search results to the AI for generating a report
report = chat_with_ai(search_results)
# Display the report
st.write(report)
if __name__ == "__main__":
main()