saherPervaiz commited on
Commit
210d38b
·
verified ·
1 Parent(s): 650d5b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -3,37 +3,34 @@ import requests
3
  import pandas as pd
4
  from sklearn.feature_extraction.text import TfidfVectorizer
5
  from sklearn.metrics.pairwise import cosine_similarity
6
- import warnings
7
-
8
- # Suppress specific warnings related to missing ScriptRunContext
9
- warnings.filterwarnings("ignore", message=".*missing ScriptRunContext.*")
10
 
11
  # Set up the Streamlit page
12
  st.title("AI Opportunity Finder for Youth")
13
  st.write("Find Scholarships, Internships, Online Courses, and more!")
14
 
15
- # Function to get scholarships data from a real API
16
  def get_scholarships(location, interests):
17
  # Example: Using a mock API or replace it with a real API URL
18
- # For now, we will use JSONPlaceholder for demonstration
19
  url = "https://jsonplaceholder.typicode.com/posts" # Mock API
20
  response = requests.get(url)
21
 
22
  if response.status_code == 200:
23
- # Sample response (You should replace this with real scholarship data)
24
- return [{"title": f"Scholarship {i+1}", "description": post['body'], "eligibility": "Any student from any background."} for i, post in enumerate(response.json())[:5]]
 
 
25
  else:
26
  return []
27
 
28
- # Function to get internships data from a real API
29
  def get_internships():
30
- # Example: Using a mock API or replace it with a real API URL
31
- url = "https://jsonplaceholder.typicode.com/posts" # Mock API
32
  response = requests.get(url)
33
 
34
  if response.status_code == 200:
35
- # Sample response (You should replace this with real internship data)
36
- return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": post['body']} for i, post in enumerate(response.json())[:5]]
37
  else:
38
  return []
39
 
@@ -108,17 +105,3 @@ if st.sidebar.button("Get AI Recommendations"):
108
  st.write(f"Description: {opportunity['description']}")
109
  st.write(f"Eligibility: {opportunity.get('eligibility', 'Not available')}")
110
  st.write("---")
111
-
112
- # Your main logic here
113
- def main():
114
- try:
115
- # Your main code logic
116
- pass
117
- except Exception as e:
118
- st.error(f"Error occurred: {e}")
119
- finally:
120
- # Cleanup actions if necessary
121
- pass
122
-
123
- if __name__ == "__main__":
124
- main()
 
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(location, interests):
13
  # Example: Using a mock API or replace it with a real API URL
 
14
  url = "https://jsonplaceholder.typicode.com/posts" # Mock API
15
  response = requests.get(url)
16
 
17
  if response.status_code == 200:
18
+ # Convert the response to a list and limit to the first 5 items
19
+ posts = response.json()[:5]
20
+ # Construct scholarships list
21
+ return [{"title": f"Scholarship {i+1}", "description": post['body'], "eligibility": "Any student from any background."} for i, post in enumerate(posts)]
22
  else:
23
  return []
24
 
25
+ # Function to get internships data from a mock API
26
  def get_internships():
27
+ # Example: Using a mock API for Internships (replace with a real API)
28
+ url = "https://jsonplaceholder.typicode.com/posts" # Mock API for testing
29
  response = requests.get(url)
30
 
31
  if response.status_code == 200:
32
+ # Return a list of mock internships
33
+ return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of the internship."} for i in range(5)]
34
  else:
35
  return []
36
 
 
105
  st.write(f"Description: {opportunity['description']}")
106
  st.write(f"Eligibility: {opportunity.get('eligibility', 'Not available')}")
107
  st.write("---")