Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,50 @@
|
|
1 |
-
import os
|
2 |
-
import streamlit as st
|
3 |
-
from groq import Groq
|
4 |
import asyncio
|
|
|
5 |
from googletrans import Translator
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
# Fetch the API key from the environment variable
|
10 |
-
api_key = "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"
|
11 |
-
|
12 |
-
if not api_key:
|
13 |
-
raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
|
14 |
-
|
15 |
-
# Initialize the Groq client with the API key
|
16 |
-
client = Groq(api_key=api_key)
|
17 |
-
|
18 |
-
# Construct the query
|
19 |
-
query = f"Based on the user's interests in {user_interests}, skills in {user_skills}, and location of {user_location}, find scholarships, internships, online courses, and career advice suitable for them."
|
20 |
-
|
21 |
-
# Request to Groq API
|
22 |
-
response = client.chat.completions.create(
|
23 |
-
messages=[{"role": "user", "content": query}],
|
24 |
-
model="llama-3.3-70b-versatile",
|
25 |
-
)
|
26 |
-
|
27 |
-
return response.choices[0].message.content
|
28 |
|
29 |
-
#
|
30 |
-
def translate_text(text, target_language):
|
31 |
translator = Translator()
|
32 |
-
|
|
|
33 |
return translated.text
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
st.markdown("""
|
41 |
-
<style>
|
42 |
-
.css-1v0mbdj {padding-top: 30px; font-size: 1.5rem;}
|
43 |
-
.css-1wa3m6h {padding: 10px; background-color: #f0f0f5;}
|
44 |
-
.css-1w4t6pm {border: 1px solid #ccc; padding: 10px; background-color: #fff;}
|
45 |
-
.css-1f4y1re {font-size: 1.2rem;}
|
46 |
-
</style>
|
47 |
-
""", unsafe_allow_html=True)
|
48 |
|
49 |
-
#
|
50 |
-
|
|
|
51 |
|
52 |
-
#
|
53 |
-
interests = st.
|
54 |
-
skills = st.
|
55 |
-
location = st.
|
56 |
|
57 |
-
#
|
58 |
-
|
59 |
"English": "English",
|
60 |
"Spanish": "Spanish",
|
61 |
"French": "French",
|
@@ -66,38 +55,23 @@ languages = {
|
|
66 |
"Urdu": "Urdu" # Full word for Urdu
|
67 |
}
|
68 |
|
69 |
-
selected_language = st.
|
70 |
-
|
71 |
-
# Container to display results
|
72 |
-
results_container = st.container()
|
73 |
|
74 |
-
#
|
75 |
-
if st.
|
76 |
-
|
77 |
-
with st.spinner("Fetching opportunities..."):
|
78 |
-
# Fetch recommendations using the Groq API
|
79 |
opportunities = get_opportunities(interests, skills, location)
|
80 |
-
|
81 |
-
# Translate the opportunities based on the selected language
|
82 |
-
translated_opportunities = translate_text(opportunities, languages[selected_language])
|
83 |
-
|
84 |
-
# Display the opportunities
|
85 |
-
results_container.subheader("Recommended Opportunities")
|
86 |
-
results_container.write(translated_opportunities)
|
87 |
-
else:
|
88 |
-
st.sidebar.error("Please fill all fields.")
|
89 |
|
90 |
-
#
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
1 |
import asyncio
|
2 |
+
import streamlit as st
|
3 |
from googletrans import Translator
|
4 |
+
from groq import Groq
|
5 |
+
import os
|
6 |
|
7 |
+
# Initialize the Groq API client
|
8 |
+
client = Groq(api_key=os.environ.get("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"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Async function for translation
|
11 |
+
async def translate_text(text, target_language):
|
12 |
translator = Translator()
|
13 |
+
# Translate text asynchronously
|
14 |
+
translated = await translator.translate(text, dest=target_language)
|
15 |
return translated.text
|
16 |
|
17 |
+
# Fetch opportunities based on user input (interests, skills, location)
|
18 |
+
def get_opportunities(interests, skills, location):
|
19 |
+
# Placeholder for real opportunity fetching logic
|
20 |
+
# In your case, this would use Groq or another API to get dynamic data
|
21 |
+
return {
|
22 |
+
'scholarships': 'Here are some scholarship opportunities...',
|
23 |
+
'internships': 'Here are some internship opportunities...',
|
24 |
+
'courses': 'Here are some courses you can explore...'
|
25 |
+
}
|
26 |
+
|
27 |
+
# Async function to get translated opportunities
|
28 |
+
async def get_translated_opportunities(opportunities, selected_language):
|
29 |
+
translated_opportunities = {}
|
30 |
+
|
31 |
+
# Translate each opportunity
|
32 |
+
for opportunity_type, opportunity_list in opportunities.items():
|
33 |
+
translated_opportunities[opportunity_type] = await translate_text(opportunity_list, selected_language)
|
34 |
|
35 |
+
return translated_opportunities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
# Main Streamlit UI code
|
38 |
+
def main():
|
39 |
+
st.title("Opportunity Finder for Youth")
|
40 |
|
41 |
+
# User input for interests, skills, and location
|
42 |
+
interests = st.text_input("Enter your interests (e.g., technology, science)")
|
43 |
+
skills = st.text_input("Enter your skills (e.g., coding, research)")
|
44 |
+
location = st.text_input("Enter your location (e.g., Lahore, Pakistan)")
|
45 |
|
46 |
+
# Dropdown to select language
|
47 |
+
language_options = {
|
48 |
"English": "English",
|
49 |
"Spanish": "Spanish",
|
50 |
"French": "French",
|
|
|
55 |
"Urdu": "Urdu" # Full word for Urdu
|
56 |
}
|
57 |
|
58 |
+
selected_language = st.selectbox("Select your language", list(language_options.keys()))
|
|
|
|
|
|
|
59 |
|
60 |
+
# Fetch opportunities based on user input
|
61 |
+
if st.button("Find Opportunities"):
|
62 |
+
if interests and skills and location:
|
|
|
|
|
63 |
opportunities = get_opportunities(interests, skills, location)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
# Async translation of opportunities
|
66 |
+
translated_opportunities = asyncio.run(get_translated_opportunities(opportunities, language_options[selected_language]))
|
67 |
+
|
68 |
+
# Display translated opportunities
|
69 |
+
st.subheader(f"Opportunities in {selected_language}:")
|
70 |
+
for opportunity_type, translated_text in translated_opportunities.items():
|
71 |
+
st.markdown(f"**{opportunity_type.capitalize()}**: {translated_text}")
|
72 |
+
else:
|
73 |
+
st.error("Please fill out all fields (interests, skills, location) to get recommendations.")
|
74 |
+
|
75 |
+
# Run the app
|
76 |
+
if __name__ == "__main__":
|
77 |
+
main()
|
|