Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -1,80 +1,69 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
-
from
|
4 |
-
from groq import Client # Assuming correct Groq API client import
|
5 |
|
6 |
-
#
|
7 |
-
API_KEY = os.
|
8 |
if not API_KEY:
|
9 |
st.error("API key is missing. Please set the GROQ_API_KEY environment variable.")
|
10 |
st.stop()
|
11 |
|
12 |
-
|
13 |
-
client = Client(api_key=API_KEY)
|
14 |
|
15 |
-
# Streamlit
|
16 |
-
st.set_page_config(page_title="AI
|
17 |
-
st.title("AI-Powered
|
18 |
|
19 |
-
# Sidebar for
|
20 |
-
st.sidebar.header("
|
21 |
-
|
22 |
-
skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):")
|
23 |
-
location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):")
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
"French": "fr",
|
30 |
-
"German": "de",
|
31 |
-
"Italian": "it",
|
32 |
-
"Chinese": "zh-cn",
|
33 |
-
"Japanese": "ja",
|
34 |
-
"Urdu": "ur",
|
35 |
-
}
|
36 |
-
selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys()))
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
f"
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
model="llama-3.3-70b-versatile",
|
48 |
-
)
|
49 |
-
return response.choices[0].message.content
|
50 |
-
except Exception as e:
|
51 |
-
st.error(f"Error fetching opportunities: {e}")
|
52 |
-
return None
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
st.subheader("Recommended Opportunities")
|
70 |
-
st.write(translated_opportunities)
|
71 |
else:
|
72 |
-
st.
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Footer
|
75 |
st.markdown("""
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
</footer>
|
80 |
-
""", unsafe_allow_html=True)
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
+
from groq import Groq
|
|
|
4 |
|
5 |
+
# Initialize Groq client
|
6 |
+
API_KEY = os.getenv("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") # Ensure GROQ_API_KEY is set in your environment variables
|
7 |
if not API_KEY:
|
8 |
st.error("API key is missing. Please set the GROQ_API_KEY environment variable.")
|
9 |
st.stop()
|
10 |
|
11 |
+
client = Groq(api_key=API_KEY)
|
|
|
12 |
|
13 |
+
# Streamlit app configuration
|
14 |
+
st.set_page_config(page_title="AI Chatbot", page_icon="🤖", layout="wide")
|
15 |
+
st.title("AI-Powered Chatbot with Groq")
|
16 |
|
17 |
+
# Sidebar for user input
|
18 |
+
st.sidebar.header("Chatbot Settings")
|
19 |
+
chat_model = st.sidebar.selectbox("Select AI Model", ["llama-3.3-70b-versatile", "llama-2.0-50b-creative"])
|
|
|
|
|
20 |
|
21 |
+
# Chat interface
|
22 |
+
st.write("## Chat with AI")
|
23 |
+
if "messages" not in st.session_state:
|
24 |
+
st.session_state.messages = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# Display conversation history
|
27 |
+
for msg in st.session_state.messages:
|
28 |
+
if msg["role"] == "user":
|
29 |
+
st.write(f"**You:** {msg['content']}")
|
30 |
+
else:
|
31 |
+
st.write(f"**AI:** {msg['content']}")
|
32 |
+
|
33 |
+
# User input for the chatbot
|
34 |
+
user_input = st.text_input("Enter your message:", key="user_input")
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# On submit, process the input
|
37 |
+
if st.button("Send"):
|
38 |
+
if user_input:
|
39 |
+
# Add user input to the chat history
|
40 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
41 |
+
|
42 |
+
# Call Groq API
|
43 |
+
with st.spinner("Thinking..."):
|
44 |
+
try:
|
45 |
+
chat_completion = client.chat.completions.create(
|
46 |
+
messages=st.session_state.messages,
|
47 |
+
model=chat_model,
|
48 |
+
)
|
49 |
+
ai_response = chat_completion.choices[0].message.content
|
50 |
|
51 |
+
# Add AI response to the chat history
|
52 |
+
st.session_state.messages.append({"role": "assistant", "content": ai_response})
|
53 |
+
|
54 |
+
# Display the AI's response
|
55 |
+
st.write(f"**AI:** {ai_response}")
|
56 |
+
except Exception as e:
|
57 |
+
st.error(f"Error: {e}")
|
|
|
|
|
58 |
else:
|
59 |
+
st.warning("Please enter a message before sending.")
|
60 |
+
|
61 |
+
# Clear conversation button
|
62 |
+
if st.button("Clear Conversation"):
|
63 |
+
st.session_state.messages = []
|
64 |
|
65 |
# Footer
|
66 |
st.markdown("""
|
67 |
+
---
|
68 |
+
Powered by [Groq](https://groq.com) | Deployed on [Hugging Face Spaces](https://huggingface.co/spaces)
|
69 |
+
""")
|
|
|
|