Tanseer45203 commited on
Commit
33089a8
·
verified ·
1 Parent(s): e7d9560

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load API key
7
+ load_dotenv()
8
+ API_KEY = os.getenv("GROQ_API_KEY")
9
+
10
+ # Initialize Groq client
11
+ client = Groq(api_key=API_KEY)
12
+
13
+ # Streamlit App Title
14
+ st.set_page_config(page_title="Life Experience Chatbot", layout="centered")
15
+ st.title("🌍 AI Life Experience Chatbot")
16
+
17
+ # Styling for mobile responsiveness
18
+ st.markdown(
19
+ """
20
+ <style>
21
+ body { font-size: 18px; }
22
+ .stTextArea textarea { font-size: 16px !important; }
23
+ .stButton button { font-size: 16px !important; padding: 10px; }
24
+ </style>
25
+ """,
26
+ unsafe_allow_html=True,
27
+ )
28
+
29
+ # List of Life Topics
30
+ life_topics = [
31
+ "Police Life", "Student Life", "Engineer Life", "Doctor Life", "Shopkeeper Life", "Labour Life", "Freeman Life",
32
+ "Hostel Life", "Home Life", "Karachi Life", "Islamabad Life", "Tharimirwah Life", "Khairpur Life", "Pith Ghoth Life",
33
+ "Sukkur Life", "Ghotki Life", "Rancour Life", "Pakistan Life", "Qatar Life", "Saudi Life", "Iron Life"
34
+ ]
35
+
36
+ # Select a Topic
37
+ selected_life = st.selectbox("Choose a Life Experience to Explore:", life_topics)
38
+
39
+ # User Input for Customization
40
+ user_input = st.text_area("Ask about this lifestyle (optional):", placeholder="E.g., 'What challenges do police officers face?'")
41
+
42
+ # Generate AI Response Button
43
+ if st.button("Get AI Insight"):
44
+ user_prompt = f"Describe the lifestyle of {selected_life}. {user_input if user_input else ''}"
45
+
46
+ try:
47
+ response = client.chat.completions.create(
48
+ model="llama-3.3-70b-versatile",
49
+ messages=[{"role": "user", "content": user_prompt}]
50
+ )
51
+ st.write("### 📝 AI-Generated Insight:")
52
+ st.write(response.choices[0].message.content)
53
+ except Exception as e:
54
+ st.error(f"Error: {e}")