dwfefef commited on
Commit
875c158
·
verified ·
1 Parent(s): f8be49a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -42
app.py CHANGED
@@ -1,42 +1,61 @@
1
- import streamlit as st
2
- from backend import generate_research_report
3
-
4
- st.set_page_config(page_title="Echo - Your Research Assistant", page_icon="🔍")
5
-
6
- st.title("Echo - Your Research Assistant 🤖📚")
7
-
8
- st.write("""
9
- Welcome to Echo, your AI-powered research assistant!
10
- Enter a topic, and Echo will conduct comprehensive research and generate a detailed report for you.
11
- """)
12
-
13
- # Input for research topic
14
- topic = st.text_input("Enter your research topic:", "")
15
-
16
- if st.button("Generate Report"):
17
- if topic:
18
- with st.spinner("Echo is researching and writing your report... This may take a few minutes."):
19
- try:
20
- report = generate_research_report(topic)
21
- st.success("Report generated successfully!")
22
- st.subheader("Research Report:")
23
- st.write(report)
24
- except Exception as e:
25
- st.error(f"An error occurred: {str(e)}")
26
- else:
27
- st.warning("Please enter a research topic.")
28
-
29
- st.sidebar.header("About Echo")
30
- st.sidebar.write("""
31
- Echo is an AI-powered research assistant that uses advanced language models and web search capabilities to generate comprehensive reports on any topic you provide.
32
-
33
- How it works:
34
- 1. You enter a research topic.
35
- 2. Echo searches the web for relevant information.
36
- 3. Echo synthesizes the findings into a well-structured report.
37
- 4. You receive a detailed, easy-to-understand research report.
38
-
39
- Echo is powered by CrewAI and uses custom language models to ensure high-quality results.
40
- """)
41
-
42
- st.sidebar.info("Note: This is a prototype version. Results may vary, and the research process may take a few minutes.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from g4f.client import Client
3
+ from g4f.api import run_api
4
+
5
+ app = Flask(__name__)
6
+
7
+ system_message = """ ## Role
8
+ Act as a mental health assistant named Sonia, developed by Abhinav, who communicates in Hinglish with a Gen Z style, providing kind and helpful support.
9
+ ## Task
10
+ Engage with users in a friendly and supportive manner, offering mental health tips, resources, and encouragement. Use your expertise in mental well-being to create a safe space for users to discuss their feelings and challenges.
11
+ ## Specifics
12
+ - Respond to user queries about mental health with empathy and understanding.
13
+ - Provide information on coping strategies, self-care techniques, and resources for mental health support.
14
+ - Use relatable language and examples that resonate with a Gen Z audience.
15
+ - Incorporate positive affirmations and motivational quotes to uplift users.
16
+ - Maintain a conversational flow, encouraging users to express themselves openly.
17
+ ## Content Guidelines
18
+ - Ensure all mental health information is accurate and based on reputable sources.
19
+ - Use a friendly, conversational tone that feels approachable and relatable.
20
+ - Incorporate cultural references and slang that connect with the Gen Z demographic.
21
+ - Address potential questions or concerns users may have about mental health openly and honestly.
22
+ - Be kind and supportive, helping users feel understood and valued.
23
+ ## Output Format
24
+ 1. Friendly introduction from Sonia, explaining her purpose and how she can help.
25
+ 2. Responses to user queries, offering advice and encouragement.
26
+ 3. Suggestions for mental health resources (e.g., apps, websites, helplines) related to user concerns.
27
+ 4. Positive affirmations or motivational quotes to uplift users.
28
+ 5. Engagement prompts to encourage users to share their thoughts or feelings.
29
+ Output:
30
+ [Sonia will then generate friendly and supportive responses based on user input, following the guidelines above]
31
+ # Notes
32
+ - Tailor the content to resonate with the experiences and challenges faced by Gen Z individuals regarding mental health.
33
+ - Ensure that all advice provided is practical, actionable, and compassionate.
34
+ - Avoid overly clinical language; keep it relatable and simple for users to understand.
35
+ - Always prioritize creating a safe and welcoming environment for users to discuss their mental health."""
36
+
37
+ @app.route('/')
38
+ def home():
39
+ return render_template('index.html') # Serve the HTML file
40
+
41
+ @app.route('/api', methods=['POST'])
42
+ def api():
43
+ data = request.json
44
+ user_message = data.get("message", "Hello") # Default to "Hello" if no message is provided
45
+
46
+ client = Client()
47
+
48
+ try:
49
+ response = client.chat.completions.create(
50
+ model="gpt-4o",
51
+ system_message=[{"role": "system", "content": system_message}], # Fixed the spelling here
52
+ messages=[{"role": "user", "content": user_message}],
53
+ # Include any other required parameters here
54
+ )
55
+ output_message = response.choices[0].message.content
56
+ return jsonify({"message": "Data received", "response": output_message})
57
+ except Exception as e:
58
+ return jsonify({"error": str(e)}), 500 # Return an error message if something goes wrong
59
+
60
+ if __name__ == "__main__":
61
+ app.run(host='0.0.0.0', port=7860) # Port should be 7860 for Hugging Face Spaces