Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -1,124 +1,80 @@
|
|
1 |
import os
|
2 |
-
import requests
|
3 |
import streamlit as st
|
4 |
from deep_translator import GoogleTranslator
|
5 |
-
import
|
6 |
|
7 |
-
# Ensure
|
8 |
-
GROQ_API_URL = "https://api.groq.com/v1/completions" # Replace with the actual endpoint if different
|
9 |
API_KEY = os.environ.get("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")
|
10 |
-
|
11 |
if not API_KEY:
|
12 |
-
|
13 |
-
|
14 |
-
# Function to get recommendations from Groq API based on user input
|
15 |
-
def get_opportunities(user_query):
|
16 |
-
headers = {
|
17 |
-
"Authorization": f"Bearer {API_KEY}",
|
18 |
-
"Content-Type": "application/json"
|
19 |
-
}
|
20 |
-
|
21 |
-
payload = {
|
22 |
-
"model": "llama-3.3-70b-versatile", # Example model, replace with the actual model you want
|
23 |
-
"messages": [{"role": "user", "content": user_query}],
|
24 |
-
}
|
25 |
-
|
26 |
-
# Send the request to the Groq API
|
27 |
-
response = requests.post(GROQ_API_URL, json=payload, headers=headers)
|
28 |
-
|
29 |
-
if response.status_code == 200:
|
30 |
-
return response.json() # Adjust as per Groq's response format
|
31 |
-
else:
|
32 |
-
raise ValueError(f"Error fetching data from Groq API: {response.status_code}, {response.text}")
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
translated = GoogleTranslator(source='auto', target=target_language).translate(text)
|
37 |
-
return translated
|
38 |
|
39 |
-
# Streamlit App
|
40 |
-
st.set_page_config(page_title="AI-Powered Opportunity Finder",
|
41 |
st.title("AI-Powered Opportunity Finder for Youth")
|
42 |
|
43 |
-
#
|
44 |
-
st.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
.css-1w4t6pm {border: 1px solid #ccc; padding: 10px; background-color: #fff;}
|
49 |
-
.css-1f4y1re {font-size: 1.2rem;}
|
50 |
-
</style>
|
51 |
-
""", unsafe_allow_html=True)
|
52 |
|
53 |
-
#
|
54 |
-
st.sidebar.header("Ask the AI Chatbot for Opportunities")
|
55 |
-
|
56 |
-
# Language selection
|
57 |
languages = {
|
58 |
"English": "en",
|
59 |
"Spanish": "es",
|
60 |
"French": "fr",
|
61 |
"German": "de",
|
62 |
"Italian": "it",
|
63 |
-
"Chinese": "zh",
|
64 |
"Japanese": "ja",
|
65 |
-
"Urdu": "ur"
|
66 |
}
|
67 |
-
|
68 |
selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys()))
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
# Button to
|
85 |
-
if st.button("
|
86 |
-
if
|
87 |
-
# Append user query to chat history
|
88 |
-
st.session_state.messages.append({"role": "user", "content": user_query})
|
89 |
-
|
90 |
with st.spinner("Fetching opportunities..."):
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
opportunities_text = opportunities_response.get("choices", [{}])[0].get("message", {}).get("content", "No data found.")
|
97 |
-
|
98 |
-
# Run the async translate function and get the translated text
|
99 |
-
translated_opportunities = asyncio.run(translate_text(opportunities_text, languages[selected_language]))
|
100 |
-
|
101 |
-
# Append AI response to chat history
|
102 |
-
st.session_state.messages.append({"role": "ai", "content": translated_opportunities})
|
103 |
-
except Exception as e:
|
104 |
-
st.error(f"Error: {e}")
|
105 |
-
|
106 |
-
# Scroll to the latest message
|
107 |
-
st.experimental_rerun()
|
108 |
else:
|
109 |
-
st.error("Please
|
110 |
|
111 |
-
#
|
112 |
st.markdown("""
|
113 |
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
|
114 |
-
<p>Powered by Groq, Google
|
115 |
-
<p>For more opportunities, visit:</p>
|
116 |
-
<ul style="list-style-type:none; padding: 0;">
|
117 |
-
<li><a href="https://www.groq.com" target="_blank">Groq - AI Solutions</a></li>
|
118 |
-
<li><a href="https://www.scholarships.com" target="_blank">Scholarships.com</a></li>
|
119 |
-
<li><a href="https://www.coursera.org" target="_blank">Coursera - Online Courses</a></li>
|
120 |
-
<li><a href="https://www.linkedin.com/jobs" target="_blank">LinkedIn Jobs</a></li>
|
121 |
-
</ul>
|
122 |
<p>Contact: [email protected]</p>
|
123 |
</footer>
|
124 |
""", unsafe_allow_html=True)
|
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
3 |
from deep_translator import GoogleTranslator
|
4 |
+
from groq import Client # Assuming correct Groq API client import
|
5 |
|
6 |
+
# Ensure the API key is set
|
|
|
7 |
API_KEY = os.environ.get("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")
|
|
|
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 |
+
# Initialize the Groq client
|
13 |
+
client = Client(api_key=API_KEY)
|
|
|
|
|
14 |
|
15 |
+
# Streamlit App
|
16 |
+
st.set_page_config(page_title="AI-Powered Opportunity Finder", layout="wide")
|
17 |
st.title("AI-Powered Opportunity Finder for Youth")
|
18 |
|
19 |
+
# Sidebar for inputs
|
20 |
+
st.sidebar.header("Provide your details to find opportunities")
|
21 |
+
interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):")
|
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 |
+
# Language selection for translation
|
|
|
|
|
|
|
26 |
languages = {
|
27 |
"English": "en",
|
28 |
"Spanish": "es",
|
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 |
+
# Main functionality
|
39 |
+
def fetch_opportunities(user_interests, user_skills, user_location):
|
40 |
+
query = (
|
41 |
+
f"Based on the user's interests in {user_interests}, skills in {user_skills}, "
|
42 |
+
f"and location of {user_location}, find scholarships, internships, online courses, and career advice."
|
43 |
+
)
|
44 |
+
try:
|
45 |
+
response = client.chat.completions.create(
|
46 |
+
messages=[{"role": "user", "content": query}],
|
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 |
+
def translate_text(text, target_language):
|
55 |
+
try:
|
56 |
+
translator = GoogleTranslator(target=target_language)
|
57 |
+
return translator.translate(text)
|
58 |
+
except Exception as e:
|
59 |
+
st.error(f"Error translating text: {e}")
|
60 |
+
return text
|
61 |
|
62 |
+
# Button to fetch opportunities
|
63 |
+
if st.sidebar.button("Find Opportunities"):
|
64 |
+
if interests and skills and location:
|
|
|
|
|
|
|
65 |
with st.spinner("Fetching opportunities..."):
|
66 |
+
opportunities = fetch_opportunities(interests, skills, location)
|
67 |
+
if opportunities:
|
68 |
+
translated_opportunities = translate_text(opportunities, languages[selected_language])
|
69 |
+
st.subheader("Recommended Opportunities")
|
70 |
+
st.write(translated_opportunities)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
else:
|
72 |
+
st.sidebar.error("Please fill in all fields.")
|
73 |
|
74 |
+
# Footer
|
75 |
st.markdown("""
|
76 |
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
|
77 |
+
<p>Powered by Groq, Google Translator, and Streamlit</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
<p>Contact: [email protected]</p>
|
79 |
</footer>
|
80 |
""", unsafe_allow_html=True)
|