saherPervaiz commited on
Commit
851c6af
·
verified ·
1 Parent(s): 8c40a7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -79
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
- # Function to get recommendations from Groq AI based on user input
8
- def get_opportunities(user_interests, user_skills, user_location):
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
- # Function to translate text into the selected language
30
- def translate_text(text, target_language):
31
  translator = Translator()
32
- translated = translator.translate(text, dest=target_language)
 
33
  return translated.text
34
 
35
- # Streamlit App Interface
36
- st.set_page_config(page_title="AI-Powered Opportunity Finder", page_icon=":bulb:", layout="wide")
37
- st.title("AI-Powered Opportunity Finder for Youth")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- # Custom CSS for improving the UI
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
- # Sidebar for input fields
50
- st.sidebar.header("Provide your details to find opportunities")
 
51
 
52
- # Collect user input for interests, skills, and location in the sidebar
53
- interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):")
54
- skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):")
55
- location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):")
56
 
57
- # Language selection
58
- languages = {
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.sidebar.selectbox("Select your preferred language:", list(languages.keys()))
70
-
71
- # Container to display results
72
- results_container = st.container()
73
 
74
- # Button to fetch opportunities
75
- if st.sidebar.button("Find Opportunities"):
76
- if interests and skills and location:
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
- # Add a footer with contact info and clickable links
91
- st.markdown("""
92
- <footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
93
- <p>Powered by Groq, Google Translate, and Streamlit</p>
94
- <p>For more opportunities, visit:</p>
95
- <ul style="list-style-type:none; padding: 0;">
96
- <li><a href="https://www.groq.com" target="_blank">Groq - AI Solutions</a></li>
97
- <li><a href="https://www.scholarships.com" target="_blank">Scholarships.com</a></li>
98
- <li><a href="https://www.coursera.org" target="_blank">Coursera - Online Courses</a></li>
99
- <li><a href="https://www.linkedin.com/jobs" target="_blank">LinkedIn Jobs</a></li>
100
- </ul>
101
- <p>Contact: support@example.com</p>
102
- </footer>
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()