|
import streamlit as st |
|
import requests |
|
|
|
|
|
session = requests.Session() |
|
|
|
|
|
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') |
|
else: |
|
return {"error": "Failed to get a response from the AI API."} |
|
except requests.RequestException as e: |
|
return {"error": f"Error: {e}"} |
|
|
|
|
|
def web_search(query): |
|
url = "https://free-ai-api.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}"} |
|
|
|
|
|
def main(): |
|
st.title("HelpingAI Research Assistant") |
|
|
|
query = st.text_input("Enter your research query: ") |
|
|
|
if st.button("Generate Report"): |
|
if query: |
|
|
|
search_results = web_search(query) |
|
|
|
|
|
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" |
|
report = chat_with_ai(prompt) |
|
|
|
|
|
st.write(report) |
|
else: |
|
st.write("Please enter a research query.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|