saherPervaiz commited on
Commit
ab78615
·
verified ·
1 Parent(s): b35077f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +124 -0
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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": "This is a sample description.", "eligibility": "Any student from any background."} for i in range(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": "Description of the internship."} for i in range(5)]
37
+ else:
38
+ return []
39
+
40
+ # Function to recommend opportunities based on user input
41
+ def recommend_opportunities(user_interests, user_skills, opportunities):
42
+ # Combine user profile into a single string
43
+ user_profile = [f"{user_interests} {user_skills}"]
44
+
45
+ # Create text data for opportunities based on description & eligibility
46
+ opportunities_text = [f"{opportunity['description']} {opportunity['eligibility']}" for opportunity in opportunities]
47
+
48
+ # Vectorize the text using TF-IDF
49
+ vectorizer = TfidfVectorizer(stop_words='english')
50
+ tfidf_matrix = vectorizer.fit_transform(opportunities_text + user_profile)
51
+
52
+ # Compute cosine similarity
53
+ cosine_sim = cosine_similarity(tfidf_matrix[-1], tfidf_matrix[:-1])
54
+
55
+ # Get the indices of the top 5 recommended opportunities
56
+ recommendations = cosine_sim[0].argsort()[-5:][::-1]
57
+
58
+ # Return recommended opportunities
59
+ return [opportunities[i] for i in recommendations]
60
+
61
+ # User input for profile
62
+ st.sidebar.header("User Profile")
63
+ location = st.sidebar.text_input("Location", "Pakistan") # Default to 'Pakistan'
64
+ skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
65
+ interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")
66
+
67
+ # Fetch scholarships based on user input
68
+ scholarships = get_scholarships(location, interests)
69
+
70
+ # Display scholarships if available
71
+ if scholarships:
72
+ st.write("Scholarships found:")
73
+ for scholarship in scholarships:
74
+ st.write(f"Title: {scholarship['title']}")
75
+ st.write(f"Description: {scholarship['description']}")
76
+ st.write(f"Eligibility: {scholarship['eligibility']}")
77
+ st.write("---")
78
+ else:
79
+ st.write("No scholarships found based on your criteria.")
80
+
81
+ # Fetch internships based on user input
82
+ internships = get_internships()
83
+
84
+ # Display internships if available
85
+ if internships:
86
+ st.write("Internships found:")
87
+ for internship in internships:
88
+ st.write(f"Title: {internship['jobtitle']}")
89
+ st.write(f"Company: {internship['company']}")
90
+ st.write(f"Location: {internship['location']}")
91
+ st.write(f"Snippet: {internship['snippet']}")
92
+ st.write("---")
93
+ else:
94
+ st.write("No internships found.")
95
+
96
+ # AI-based recommendations for opportunities
97
+ if st.sidebar.button("Get AI Recommendations"):
98
+ # Combine scholarships and internships for recommendations
99
+ all_opportunities = scholarships + internships
100
+
101
+ # Get AI recommendations based on user input
102
+ recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities)
103
+
104
+ # Display recommended opportunities
105
+ st.write("Recommended Opportunities based on your profile:")
106
+ for opportunity in recommended_opportunities:
107
+ st.write(f"Title: {opportunity['title']}")
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()