saherPervaiz commited on
Commit
53a1988
·
verified ·
1 Parent(s): 52fcd5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -44
app.py CHANGED
@@ -1,51 +1,39 @@
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}")
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import os
3
+ from groq import Groq
4
 
5
+ # Function to get recommendations from Groq AI based on user input
6
+ def get_opportunities(user_interests, user_skills, user_location):
7
+ # Initialize Groq client using API key from environment variable
8
+ client = Groq(api_key=os.environ.get("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"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Call Groq's recommendation system (chat API or similar)
11
+ response = client.chat.completions.create(
12
+ messages=[{
13
+ "role": "user",
14
+ "content": f"Find me opportunities like scholarships, internships, online courses, and career advice based on my interests: {user_interests}, skills: {user_skills}, and location: {user_location}"
15
+ }],
16
+ model="llama-3.3-70b-versatile", # You can adjust the model if needed
17
+ )
18
 
19
+ return response.choices[0].message.content
 
 
20
 
21
+ # Streamlit App Interface
22
+ st.title("AI-Powered Opportunity Finder for Youth")
 
 
 
 
 
 
 
23
 
24
+ # Collect user input for interests, skills, and location
25
+ interests = st.text_input("Enter your interests (e.g., AI, Robotics, Software Engineering):")
26
+ skills = st.text_input("Enter your skills (e.g., Python, Data Science, Web Development):")
27
+ location = st.text_input("Enter your location (e.g., Gujrat, Pakistan):")
 
 
 
28
 
29
+ # Button to fetch opportunities
30
+ if st.button("Find Opportunities"):
31
+ if interests and skills and location:
32
+ # Fetch recommendations using the Groq API
33
+ opportunities = get_opportunities(interests, skills, location)
34
+
35
+ # Display the opportunities
36
+ st.subheader("Recommended Opportunities")
37
+ st.write(opportunities)
38
+ else:
39
+ st.error("Please fill all fields.")