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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -82
app.py CHANGED
@@ -1,90 +1,51 @@
1
  import streamlit as st
2
  import requests
 
3
 
4
- # Set up the Streamlit page
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...")
 
1
  import streamlit as st
2
  import requests
3
+ from transformers import pipeline
4
 
5
+ # Initialize the language model (Hugging Face's pre-trained model for text generation)
6
+ generator = pipeline('text-generation', model='gpt-2') # You can choose any suitable language model
 
7
 
8
+ # Title and Description of the App
9
+ st.title("AI-powered Opportunity Finder for Youth")
10
+ st.write("Find scholarships, internships, competitions, and more based on your skills and interests using AI!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Collect user input
13
+ interests = st.text_input("Enter your interests (e.g., AI, web development, etc.)")
14
+ skills = st.text_input("Enter your skills (e.g., Python, Data Analysis, etc.)")
15
+ location = st.text_input("Enter your location")
16
+
17
+ # Button to trigger the AI recommendations
18
+ if st.button("Find Opportunities"):
19
+ # Combine the input into a prompt for the language model
20
+ prompt = f"Find scholarships, internships, competitions, and online courses for a person interested in {interests}, skilled in {skills}, and located in {location}. Provide recommendations with details like title, link, and description."
21
 
22
+ # Use the language model to generate recommendations
23
+ response = generator(prompt, max_length=150, num_return_sequences=1)
 
 
 
24
 
25
+ # Parse and display the generated text
26
+ recommendations = response[0]['generated_text']
27
 
28
+ # Display the generated recommendations
29
+ st.write("Recommended Opportunities based on your input:")
30
+ st.write(recommendations)
31
+
32
+ # Example to further integrate Groq API (if you need more personalized results)
33
+ # You can replace the following code with an actual API request to Groq for more detailed results
34
+ # Make sure to replace the placeholder with your Groq API endpoint and parameters
35
+ try:
36
+ api_response = requests.post("https://api.groq.com/recommendations", json={
37
+ "interests": interests,
38
+ "skills": skills,
39
+ "location": location
40
+ })
41
+
42
+ if api_response.status_code == 200:
43
+ api_recommendations = api_response.json()
44
+ st.write("Groq API Recommendations:")
45
+ for rec in api_recommendations:
46
+ st.write(f"- {rec['title']}: {rec['link']}")
47
+ else:
48
+ st.write("Unable to fetch recommendations from Groq API.")
49
+
50
+ except Exception as e:
51
+ st.write(f"Error while fetching recommendations from Groq API: {e}")