File size: 3,495 Bytes
a3c8aff
d5f4461
 
 
b6d5012
 
d5f4461
 
 
 
4e15bfb
a3c8aff
4e15bfb
d5f4461
 
 
 
 
 
aebe303
d5f4461
aebe303
d5f4461
 
 
a3c8aff
d5f4461
 
 
 
b4fac10
d5f4461
aebe303
d5f4461
 
 
f9f589b
64375ed
 
 
 
 
ab28846
 
 
 
 
 
3cedb2a
ab28846
38d828d
 
 
 
 
 
 
 
 
e5c7673
 
 
64375ed
71cce77
64375ed
 
 
71cce77
 
aebe303
64375ed
4e15bfb
71cce77
 
aebe303
 
 
 
ab28846
 
 
71cce77
64375ed
d5f4461
 
b4fac10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import streamlit as st
import requests

#hello world

# Create a session for reusing connections
session = requests.Session()

# Function to interact with the AI
def chat_with_ai(message, user_input):
    api_url = os.getenv("CHAT_API_URL")
    payload = {"message": message, "user_input": user_input}

    try:
        with session.post(api_url, json=payload) as response:
            if response.status_code == 200:
                return response.json().get('response')  # Access 'response' key
            else:
                st.error("Failed to get a response from the AI API. 😞")
    except requests.RequestException as e:
        st.error(f"Error: {e}")

# Function to perform web search
def web_search(query):
    url = os.getenv("SEARCH_API_URL")
    payload = {"query": query}
    response = requests.post(url, json=payload)

    if response.status_code == 200:
        return response.json()
    else:
        st.error(f"Error: {response.status_code}")

# Main function
def main():
    st.set_page_config(page_title='HelpingAI Research Assistant', page_icon=":mag:")
    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: helpingai5@gmail.com.")

    st.sidebar.markdown("---")
    st.sidebar.header("🌐 How to Get Webscout API")
    st.sidebar.info("""
    1. Sign up for a RapidAPI account if you haven't already.
    2. Subscribe to the "webscout-api" on the RapidAPI marketplace to acquire your API key.
    3. Choose the pricing tier that best fits your usage needs and budget.
    4. Integrate the API into your applications using the provided endpoints.
    """)

    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 detailed research report based on the following information: {search_results}. The user's query was: '{query}'. Please include an overview, key findings, and any relevant details in the report. 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, query)
            
            # Display the report
            if isinstance(report, dict) and 'error' in report:
                st.error(report['error'])
            else:
                st.write(report)

            # Update recent reports
            recent_reports.text(query)
        else:
            st.sidebar.error("❗ Please enter a research query.")

if __name__ == "__main__":
    main()