saherPervaiz commited on
Commit
1b0456d
·
verified ·
1 Parent(s): e95727f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -77
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- import streamlit as st
3
  from groq import Groq
4
  from googletrans import Translator
5
  import asyncio
@@ -51,84 +51,79 @@ def get_chatbot_response(user_message):
51
 
52
  return response.choices[0].message.content
53
 
54
- # Streamlit App Interface
55
- st.set_page_config(page_title="AI-Powered Opportunity Finder", page_icon=":bulb:", layout="wide")
56
- st.title("AI-Powered Opportunity Finder for Youth")
57
-
58
- # Custom CSS for improving the UI
59
- st.markdown("""
60
- <style>
61
- .css-1v0mbdj {padding-top: 30px; font-size: 1.5rem;}
62
- .css-1wa3m6h {padding: 10px; background-color: #f0f0f5;}
63
- .css-1w4t6pm {border: 1px solid #ccc; padding: 10px; background-color: #fff;}
64
- .css-1f4y1re {font-size: 1.2rem;}
65
- </style>
66
- """, unsafe_allow_html=True)
67
-
68
- # Sidebar for input fields
69
- st.sidebar.header("Provide your details to find opportunities")
70
-
71
- # Collect user input for interests, skills, and location in the sidebar
72
- interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):")
73
- skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):")
74
- location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):")
75
-
76
- # Language selection
77
- languages = {
78
- "English": "English",
79
- "Spanish": "Spanish",
80
- "French": "French",
81
- "German": "German",
82
- "Italian": "Italian",
83
- "Chinese": "Chinese",
84
- "Japanese": "Japanese",
85
- "Urdu": "Urdu" # Full word for Urdu
86
- }
87
-
88
- selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys()))
89
-
90
- # Container to display results
91
- results_container = st.container()
92
 
93
- # Chatbot container
94
- chatbot_container = st.container()
 
95
 
96
- # Button to fetch opportunities
97
- if st.sidebar.button("Find Opportunities"):
98
- if interests and skills and location:
99
- with st.spinner("Fetching opportunities..."):
100
- # Fetch recommendations using the Groq API
101
- opportunities = get_opportunities(interests, skills, location)
102
-
103
- # Run the async translate function and get the translated text
104
- translated_opportunities = asyncio.run(translate_text(opportunities, languages[selected_language]))
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
- # Display the opportunities
107
- results_container.subheader("Recommended Opportunities")
108
- results_container.write(translated_opportunities)
109
- else:
110
- st.sidebar.error("Please fill all fields.")
111
 
112
- # Chatbot functionality
113
- with chatbot_container:
114
- st.subheader("AI Chatbot")
115
- user_message = st.text_area("Ask anything to the chatbot:", "")
116
- if user_message:
117
- with st.spinner("Getting response from AI..."):
118
- chatbot_response = get_chatbot_response(user_message)
119
- st.write(f"**Chatbot Response**: {chatbot_response}")
120
 
121
- # Add a footer with contact info and clickable links
122
- st.markdown("""
123
- <footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
124
- <p>Powered by Groq, Google Translate, and Streamlit</p>
125
- <p>For more opportunities, visit:</p>
126
- <ul style="list-style-type:none; padding: 0;">
127
- <li><a href="https://www.groq.com" target="_blank">Groq - AI Solutions</a></li>
128
- <li><a href="https://www.scholarships.com" target="_blank">Scholarships.com</a></li>
129
- <li><a href="https://www.coursera.org" target="_blank">Coursera - Online Courses</a></li>
130
- <li><a href="https://www.linkedin.com/jobs" target="_blank">LinkedIn Jobs</a></li>
131
- </ul>
132
- <p>Contact: [email protected]</p>
133
- </footer>
134
- """, unsafe_allow_html=True)
 
1
  import os
2
+ import gradio as gr
3
  from groq import Groq
4
  from googletrans import Translator
5
  import asyncio
 
51
 
52
  return response.choices[0].message.content
53
 
54
+ # Gradio interface
55
+ with gr.Blocks(css="""
56
+ .gradio-container {
57
+ background-color: #f0f0f5;
58
+ color: #333;
59
+ font-family: 'Roboto', sans-serif;
60
+ padding: 20px;
61
+ border-radius: 10px;
62
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
63
+ }
64
+ .gradio-container .button {
65
+ background-color: #007bff;
66
+ color: white;
67
+ padding: 12px;
68
+ font-size: 16px;
69
+ border-radius: 10px;
70
+ border: none;
71
+ }
72
+ .gradio-container .button:hover {
73
+ background-color: #0056b3;
74
+ }
75
+ .gradio-container .textbox {
76
+ font-size: 16px;
77
+ padding: 12px;
78
+ border-radius: 10px;
79
+ border: 1px solid #ccc;
80
+ }
81
+ """) as demo:
82
+ gr.Markdown("""
83
+ <h1 style="text-align:center;">AI-Powered Opportunity Finder for Youth</h1>
84
+ <p style="text-align:center;">Find scholarships, internships, online courses, and career advice based on your interests, skills, and location.</p>
85
+ """)
86
+
87
+ # Sidebar for input fields
88
+ with gr.Column():
89
+ gr.Markdown("### Provide your details to find opportunities")
 
 
90
 
91
+ interests = gr.Textbox(label="Your Interests (e.g., AI, Robotics, Software Engineering):")
92
+ skills = gr.Textbox(label="Your Skills (e.g., Python, Data Science, Web Development):")
93
+ location = gr.Textbox(label="Your Location (e.g., Gujrat, Pakistan):")
94
 
95
+ languages = gr.Dropdown(
96
+ label="Select your preferred language:",
97
+ choices=["English", "Spanish", "French", "German", "Italian", "Chinese", "Japanese", "Urdu"],
98
+ value="English"
99
+ )
100
+
101
+ find_button = gr.Button("Find Opportunities")
102
+
103
+ # Chatbot Section
104
+ with gr.Column():
105
+ gr.Markdown("### AI Chatbot")
106
+ user_message = gr.Textbox(label="Ask anything to the chatbot:", lines=2)
107
+ chatbot_output = gr.Textbox(label="Chatbot Response:", interactive=False)
108
+
109
+ # Function to handle finding opportunities
110
+ def find_opportunities_and_chat(interests, skills, location, language, user_message):
111
+ # Fetch opportunities
112
+ opportunities = get_opportunities(interests, skills, location)
113
+ translated_opportunities = asyncio.run(translate_text(opportunities, language))
114
+
115
+ # Get chatbot response
116
+ chatbot_response = get_chatbot_response(user_message) if user_message else "Ask me anything!"
117
 
118
+ return translated_opportunities, chatbot_response
 
 
 
 
119
 
120
+ # Connect the button to the function
121
+ find_button.click(
122
+ find_opportunities_and_chat,
123
+ inputs=[interests, skills, location, languages, user_message],
124
+ outputs=[gr.Textbox(label="Recommended Opportunities"), chatbot_output]
125
+ )
 
 
126
 
127
+ # Launch the Gradio app
128
+ if __name__ == "__main__":
129
+ demo.launch()