Abhaykoul's picture
Update app.py
e5c7673
raw
history blame
No virus
2.84 kB
import streamlit as st
import requests
# 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://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}"}
# Main function
def main():
st.set_page_config(page_title='HelpingAI Research Assistant', page_icon=":mag:", layout='wide')
st.title("πŸ” HelpingAI Research Assistant")
st.sidebar.header("πŸ› οΈ Settings")
query = st.sidebar.text_input("πŸ”Ž Enter your research query: ")
generate_report = st.sidebar.button("πŸ“ Generate Report")
st.sidebar.markdown("---")
st.sidebar.header("πŸ“š Recent Reports")
recent_reports = st.sidebar.empty() # Placeholder for recent reports
st.sidebar.markdown("---")
st.sidebar.header("ℹ️ About this App")
st.sidebar.info("This app uses chat and web search APIs by HelpingAI. The founder of HelpingAI is Abhay Koul. The web search API used in this app is publicly available and its name is Webscout API. For any inquiries or assistance, please contact the developer: Telegram: @OEvortex, Email: koulabhay25@gmail.com.")
st.sidebar.markdown("---")
st.sidebar.markdown("Β© 2023 HelpingAI. All rights reserved.")
if generate_report:
if query:
with st.spinner('πŸ”„ Searching...'):
# Perform web search
search_results = web_search(query)
# Pass the search results to the AI for generating a report
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."
with st.spinner('πŸ”„ Generating report...'):
report = chat_with_ai(prompt)
# Display the report
st.write(report)
# Update recent reports
recent_reports.text(query)
else:
st.sidebar.error("❗ Please enter a research query.")
if __name__ == "__main__":
main()