saherPervaiz commited on
Commit
d3891bb
·
verified ·
1 Parent(s): 0c1d46f

Update app.py

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