saherPervaiz commited on
Commit
2ceeaba
·
verified ·
1 Parent(s): 8b29264

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -28
app.py CHANGED
@@ -1,37 +1,46 @@
1
  import streamlit as st
2
  import requests
3
- import pandas as pd
4
  from sklearn.feature_extraction.text import TfidfVectorizer
5
  from sklearn.metrics.pairwise import cosine_similarity
 
6
 
7
  # Set up the Streamlit page
8
  st.title("AI Opportunity Finder for Youth")
9
  st.write("Find Scholarships, Internships, Online Courses, and more!")
10
 
11
- # Function to get scholarships data from a mock API
 
 
 
 
 
 
 
 
 
 
 
12
  def get_scholarships(country, interests):
13
- # Example: Replace with a real API URL (mocked for demonstration)
14
- url = f"https://jsonplaceholder.typicode.com/posts" # Mock API
15
- response = requests.get(url)
16
 
17
- if response.status_code == 200:
18
- posts = response.json()[:5] # Take only the first 5 posts as mock scholarships
19
- return [{"title": f"Scholarship {i+1}", "description": post.get('body', 'No description available'), "eligibility": "Any student from any background."} for i, post in enumerate(posts)]
 
 
20
  else:
21
- return []
22
 
23
- # Function to get internships data from a mock API
24
  def get_internships(country):
25
- # Example: Replace with a real API URL (mocked for demonstration)
26
  url = f"https://jsonplaceholder.typicode.com/posts" # Mock API for testing
27
- response = requests.get(url)
28
-
29
- if response.status_code == 200:
30
- return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of the internship."} for i in range(5)]
 
31
  else:
32
- return []
33
 
34
- # Function to recommend opportunities based on user input
35
  def recommend_opportunities(user_interests, user_skills, opportunities):
36
  user_profile = [f"{user_interests} {user_skills}"]
37
  opportunities_text = [f"{opportunity.get('description', 'No description available')} {opportunity.get('eligibility', 'No eligibility available')}" for opportunity in opportunities]
@@ -51,9 +60,10 @@ def recommend_opportunities(user_interests, user_skills, opportunities):
51
  # Form to gather user profile and country selection
52
  with st.form(key='user_form'):
53
  st.sidebar.header("User Profile")
54
- location = st.selectbox("Select your Country", ["Pakistan", "USA", "Germany", "India", "UK", "Australia"]) # Add more countries as needed
55
  skills = st.text_input("Skills (e.g., Python, Marketing)")
56
  interests = st.text_input("Interests (e.g., Technology, Science)")
 
57
 
58
  submit_button = st.form_submit_button("Find Opportunities")
59
 
@@ -67,9 +77,13 @@ if submit_button:
67
  if scholarships:
68
  st.write("Scholarships found:")
69
  for scholarship in scholarships:
70
- st.write(f"Title: {scholarship['title']}")
71
- st.write(f"Description: {scholarship.get('description', 'No description available')}")
72
- st.write(f"Eligibility: {scholarship.get('eligibility', 'No eligibility available')}")
 
 
 
 
73
  st.write("---")
74
  else:
75
  st.write("No scholarships found for the selected country.")
@@ -78,10 +92,15 @@ if submit_button:
78
  if internships:
79
  st.write("Internships found:")
80
  for internship in internships:
81
- st.write(f"Title: {internship['jobtitle']}")
82
- st.write(f"Company: {internship['company']}")
83
- st.write(f"Location: {internship['location']}")
84
- st.write(f"Snippet: {internship['snippet']}")
 
 
 
 
 
85
  st.write("---")
86
  else:
87
  st.write("No internships found for the selected country.")
@@ -92,7 +111,11 @@ if submit_button:
92
 
93
  st.write("AI-based Recommended Opportunities based on your profile:")
94
  for opportunity in recommended_opportunities:
95
- st.write(f"Title: {opportunity['title']}")
96
- st.write(f"Description: {opportunity.get('description', 'No description available')}")
97
- st.write(f"Eligibility: {opportunity.get('eligibility', 'Not available')}")
 
 
 
 
98
  st.write("---")
 
1
  import streamlit as st
2
  import requests
 
3
  from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.metrics.pairwise import cosine_similarity
5
+ from transformers import MarianMTModel, MarianTokenizer
6
 
7
  # Set up the Streamlit page
8
  st.title("AI Opportunity Finder for Youth")
9
  st.write("Find Scholarships, Internships, Online Courses, and more!")
10
 
11
+ # Language Translation Function
12
+ def translate_text(text, target_lang='de'):
13
+ # Use Hugging Face's MarianMT for translation
14
+ model_name = f'Helsinki-NLP/opus-mt-en-{target_lang}'
15
+ model = MarianMTModel.from_pretrained(model_name)
16
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
17
+
18
+ translated = model.generate(**tokenizer(text, return_tensors="pt", padding=True, truncation=True))
19
+ translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
20
+ return translated_text
21
+
22
+ # Mock function to get data from APIs (replace with actual API calls)
23
  def get_scholarships(country, interests):
24
+ url = f"https://jsonplaceholder.typicode.com/posts" # Mock API (replace with real one)
 
 
25
 
26
+ # Simulate API response based on country
27
+ if country == "USA":
28
+ return [{"title": f"USA Scholarship {i+1}", "description": f"Description for scholarship {i+1} in USA.", "eligibility": "Any student from USA."} for i in range(5)]
29
+ elif country == "Germany":
30
+ return [{"title": f"Germany Scholarship {i+1}", "description": f"Description for scholarship {i+1} in Germany.", "eligibility": "Any student from Germany."} for i in range(5)]
31
  else:
32
+ return [{"title": f"Scholarship {i+1}", "description": f"Description for scholarship {i+1} in {country}.", "eligibility": "Any student from any background."} for i in range(5)]
33
 
 
34
  def get_internships(country):
 
35
  url = f"https://jsonplaceholder.typicode.com/posts" # Mock API for testing
36
+ # Simulate internships data
37
+ if country == "USA":
38
+ return [{"jobtitle": f"Internship {i+1}", "company": "USA Company", "location": "USA", "snippet": "Description of internship in USA."} for i in range(5)]
39
+ elif country == "Germany":
40
+ return [{"jobtitle": f"Internship {i+1}", "company": "Germany Company", "location": "Germany", "snippet": "Description of internship in Germany."} for i in range(5)]
41
  else:
42
+ return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of internship."} for i in range(5)]
43
 
 
44
  def recommend_opportunities(user_interests, user_skills, opportunities):
45
  user_profile = [f"{user_interests} {user_skills}"]
46
  opportunities_text = [f"{opportunity.get('description', 'No description available')} {opportunity.get('eligibility', 'No eligibility available')}" for opportunity in opportunities]
 
60
  # Form to gather user profile and country selection
61
  with st.form(key='user_form'):
62
  st.sidebar.header("User Profile")
63
+ location = st.selectbox("Select your Country", ["USA", "Germany", "UK", "India", "Australia", "Pakistan"]) # You can add more countries here
64
  skills = st.text_input("Skills (e.g., Python, Marketing)")
65
  interests = st.text_input("Interests (e.g., Technology, Science)")
66
+ target_language = st.selectbox("Select target language", ['de', 'fr', 'es', 'it', 'pt']) # Available language codes for translation
67
 
68
  submit_button = st.form_submit_button("Find Opportunities")
69
 
 
77
  if scholarships:
78
  st.write("Scholarships found:")
79
  for scholarship in scholarships:
80
+ title = translate_text(scholarship.get('title', 'No title available'), target_language)
81
+ description = translate_text(scholarship.get('description', 'No description available'), target_language)
82
+ eligibility = translate_text(scholarship.get('eligibility', 'No eligibility available'), target_language)
83
+
84
+ st.write(f"Title: {title}")
85
+ st.write(f"Description: {description}")
86
+ st.write(f"Eligibility: {eligibility}")
87
  st.write("---")
88
  else:
89
  st.write("No scholarships found for the selected country.")
 
92
  if internships:
93
  st.write("Internships found:")
94
  for internship in internships:
95
+ title = translate_text(internship.get('jobtitle', 'No title available'), target_language)
96
+ company = translate_text(internship.get('company', 'No company available'), target_language)
97
+ location = translate_text(internship.get('location', 'No location available'), target_language)
98
+ snippet = translate_text(internship.get('snippet', 'No snippet available'), target_language)
99
+
100
+ st.write(f"Title: {title}")
101
+ st.write(f"Company: {company}")
102
+ st.write(f"Location: {location}")
103
+ st.write(f"Snippet: {snippet}")
104
  st.write("---")
105
  else:
106
  st.write("No internships found for the selected country.")
 
111
 
112
  st.write("AI-based Recommended Opportunities based on your profile:")
113
  for opportunity in recommended_opportunities:
114
+ title = translate_text(opportunity.get('title', 'No title available'), target_language)
115
+ description = translate_text(opportunity.get('description', 'No description available'), target_language)
116
+ eligibility = translate_text(opportunity.get('eligibility', 'Not available'), target_language)
117
+
118
+ st.write(f"Title: {title}")
119
+ st.write(f"Description: {description}")
120
+ st.write(f"Eligibility: {eligibility}")
121
  st.write("---")