Spaces:
Running
Running
import streamlit as st | |
import requests | |
from transformers import pipeline | |
# Initialize the language model (Hugging Face's pre-trained model for text generation) | |
generator = pipeline('text-generation', model='gpt-2') # You can choose any suitable language model | |
# Title and Description of the App | |
st.title("AI-powered Opportunity Finder for Youth") | |
st.write("Find scholarships, internships, competitions, and more based on your skills and interests using AI!") | |
# Collect user input | |
interests = st.text_input("Enter your interests (e.g., AI, web development, etc.)") | |
skills = st.text_input("Enter your skills (e.g., Python, Data Analysis, etc.)") | |
location = st.text_input("Enter your location") | |
# Button to trigger the AI recommendations | |
if st.button("Find Opportunities"): | |
# Combine the input into a prompt for the language model | |
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." | |
# Use the language model to generate recommendations | |
response = generator(prompt, max_length=150, num_return_sequences=1) | |
# Parse and display the generated text | |
recommendations = response[0]['generated_text'] | |
# Display the generated recommendations | |
st.write("Recommended Opportunities based on your input:") | |
st.write(recommendations) | |
# Example to further integrate Groq API (if you need more personalized results) | |
# You can replace the following code with an actual API request to Groq for more detailed results | |
# Make sure to replace the placeholder with your Groq API endpoint and parameters | |
try: | |
api_response = requests.post("https://api.groq.com/recommendations", json={ | |
"interests": interests, | |
"skills": skills, | |
"location": location | |
}) | |
if api_response.status_code == 200: | |
api_recommendations = api_response.json() | |
st.write("Groq API Recommendations:") | |
for rec in api_recommendations: | |
st.write(f"- {rec['title']}: {rec['link']}") | |
else: | |
st.write("Unable to fetch recommendations from Groq API.") | |
except Exception as e: | |
st.write(f"Error while fetching recommendations from Groq API: {e}") | |