saherPervaiz commited on
Commit
51d8377
·
verified ·
1 Parent(s): 55557c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -1
app.py CHANGED
@@ -7,7 +7,151 @@ st.write("Find Scholarships, Internships, Online Courses, and more!")
7
 
8
  # Groq API URL and Authentication
9
  GROQ_API_URL = "https://api.groq.ai"
10
- API_KEY = "YOUR_GROQ_API_KEY" # Replace with your actual Groq API Key
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Function to fetch data from Groq API for scholarships
13
  def get_scholarships(location, interests):
 
7
 
8
  # Groq API URL and Authentication
9
  GROQ_API_URL = "https://api.groq.ai"
10
+ API_KEY = "import streamlit as st
11
+ import requests
12
+
13
+ # Set up the Streamlit page
14
+ st.title("AI Opportunity Finder for Youth")
15
+ st.write("Find Scholarships, Internships, Online Courses, and more!")
16
+
17
+ # Groq API URL and Authentication
18
+ GROQ_API_URL = "https://api.groq.ai"
19
+ API_KEY = "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" # Replace with your actual Groq API Key
20
+
21
+ # Function to fetch data from Groq API for scholarships
22
+ def get_scholarships(location, interests):
23
+ url = f"{GROQ_API_URL}/scholarships"
24
+ headers = {
25
+ 'Authorization': f'Bearer {API_KEY}',
26
+ 'Content-Type': 'application/json'
27
+ }
28
+ params = {"location": location, "interests": interests}
29
+
30
+ response = requests.get(url, headers=headers, params=params)
31
+
32
+ if response.status_code == 200:
33
+ scholarships = response.json()
34
+ return [{"title": scholarship['title'], "description": scholarship['description'], "eligibility": scholarship['eligibility']} for scholarship in scholarships]
35
+ else:
36
+ return []
37
+
38
+ # Function to fetch data from Groq API for internships
39
+ def get_internships():
40
+ url = f"{GROQ_API_URL}/internships"
41
+ headers = {
42
+ 'Authorization': f'Bearer {API_KEY}',
43
+ 'Content-Type': 'application/json'
44
+ }
45
+
46
+ response = requests.get(url, headers=headers)
47
+
48
+ if response.status_code == 200:
49
+ internships = response.json()
50
+ return [{"jobtitle": internship['jobtitle'], "company": internship['company'], "location": internship['location'], "snippet": internship['description']} for internship in internships]
51
+ else:
52
+ return []
53
+
54
+ # Function to recommend opportunities using Groq's recommendation system
55
+ def recommend_opportunities(user_interests, user_skills, scholarships, internships):
56
+ # Combine user interests and skills into a profile for recommendation
57
+ user_profile = f"{user_interests} {user_skills}"
58
+
59
+ # API request to get recommendations (assumed Groq API endpoint)
60
+ url = f"{GROQ_API_URL}/recommendations"
61
+ headers = {
62
+ 'Authorization': f'Bearer {API_KEY}',
63
+ 'Content-Type': 'application/json'
64
+ }
65
+
66
+ data = {
67
+ "profile": user_profile,
68
+ "opportunities": scholarships + internships
69
+ }
70
+
71
+ response = requests.post(url, json=data, headers=headers)
72
+
73
+ if response.status_code == 200:
74
+ recommended_opportunities = response.json()
75
+ return recommended_opportunities
76
+ else:
77
+ return []
78
+
79
+ # Streamlit Sidebar: User Profile Input
80
+ st.sidebar.header("User Profile")
81
+ location = st.sidebar.text_input("Location", "Pakistan") # Default to 'Pakistan'
82
+ skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
83
+ interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")
84
+
85
+ # Fetch Scholarships and Internships
86
+ scholarships = get_scholarships(location, interests)
87
+ internships = get_internships()
88
+
89
+ # Display Scholarships if available
90
+ if scholarships:
91
+ st.write("Scholarships found:")
92
+ for scholarship in scholarships:
93
+ st.write(f"**Title:** {scholarship['title']}")
94
+ st.write(f"**Description:** {scholarship['description']}")
95
+ st.write(f"**Eligibility:** {scholarship['eligibility']}")
96
+ st.write("---")
97
+ else:
98
+ st.write("No scholarships found based on your criteria.")
99
+
100
+ # Display Internships if available
101
+ if internships:
102
+ st.write("Internships found:")
103
+ for internship in internships:
104
+ st.write(f"**Title:** {internship['jobtitle']}")
105
+ st.write(f"**Company:** {internship['company']}")
106
+ st.write(f"**Location:** {internship['location']}")
107
+ st.write(f"**Snippet:** {internship['snippet']}")
108
+ st.write("---")
109
+ else:
110
+ st.write("No internships found based on your criteria.")
111
+
112
+ # AI-based Recommendations for Opportunities
113
+ if st.sidebar.button("Get AI Recommendations"):
114
+ recommended_opportunities = recommend_opportunities(interests, skills, scholarships, internships)
115
+
116
+ if recommended_opportunities:
117
+ st.write("Recommended Opportunities based on your profile:")
118
+ for opportunity in recommended_opportunities:
119
+ st.write(f"**Title:** {opportunity['title']}")
120
+ st.write(f"**Description:** {opportunity['description']}")
121
+ st.write(f"**Eligibility:** {opportunity.get('eligibility', 'Not available')}")
122
+ st.write("---")
123
+ else:
124
+ st.write("No AI recommendations found.")
125
+
126
+ # Language selection for translation (optional)
127
+ languages = {
128
+ 'English': 'en',
129
+ 'German': 'German',
130
+ 'French': 'French',
131
+ 'Spanish': 'Spanish',
132
+ 'Italian': 'Italian',
133
+ 'Portuguese': 'Portuguese',
134
+ 'Chinese': 'Chinese',
135
+ 'Arabic': 'Arabic',
136
+ 'Russian': 'Russian',
137
+ 'Japanese': 'Japanese',
138
+ 'Korean': 'Korean',
139
+ 'Urdu': 'Urdu'
140
+ }
141
+
142
+ # Dropdown for language selection
143
+ selected_language = st.selectbox("Select Language", list(languages.keys()))
144
+
145
+ # Translate text (Optional)
146
+ def translate_text(text, target_language):
147
+ # Example translation logic (replace with actual API call if necessary)
148
+ return f"Translated {text} to {target_language}"
149
+
150
+ # Display the translated text (if selected language is not English)
151
+ if selected_language != 'English':
152
+ translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language])
153
+ st.write(f"Translated Text ({selected_language}): {translated_text}")
154
+ " # Replace with your actual Groq API Key
155
 
156
  # Function to fetch data from Groq API for scholarships
157
  def get_scholarships(location, interests):