Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,46 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
|
| 5 |
+
# --- Job Data Source (Google Sheet optional) ---
|
| 6 |
+
# You can later replace this with your own Google Sheet CSV link
|
| 7 |
+
JOB_SOURCE = "https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv" # sample placeholder
|
| 8 |
|
| 9 |
+
# --- Core Chat Function ---
|
| 10 |
+
def chat_with_ai(user_input, mode):
|
| 11 |
+
# Mode-based responses
|
| 12 |
+
if mode == "Study Help":
|
| 13 |
+
return f"π StudyMate AI:\nHere's a helpful summary for your query:\n\nβ {user_input}\n\nπ‘Tip: Try asking 'Explain physics in simple Urdu'."
|
| 14 |
+
elif mode == "Job Finder":
|
| 15 |
+
try:
|
| 16 |
+
df = pd.read_csv(JOB_SOURCE)
|
| 17 |
+
results = df.sample(3)[['State', 'Rank']].to_dict('records')
|
| 18 |
+
job_list = "\n".join([f"- {r['State']} | Rank: {r['Rank']}" for r in results])
|
| 19 |
+
return f"πΌ StudyMate Job Finder:\nBased on your skill '{user_input}', here are sample job regions:\n\n{job_list}\n\n(Real data will appear once you connect your Google Sheet)"
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"β οΈ Error fetching job data: {e}"
|
| 22 |
+
else:
|
| 23 |
+
return f"π€ StudyMate AI: {user_input}"
|
| 24 |
|
| 25 |
+
# --- UI Layout ---
|
| 26 |
+
with gr.Blocks(css="""
|
| 27 |
+
body {background: radial-gradient(circle at top left, rgba(255,255,255,0.3), rgba(0,0,0,0.7));}
|
| 28 |
+
.gradio-container {backdrop-filter: blur(12px); border-radius: 20px; padding: 25px;}
|
| 29 |
+
textarea, input {border-radius: 10px !important;}
|
| 30 |
+
""") as demo:
|
| 31 |
+
gr.Markdown("## π§ StudyMate AI β Learn, Grow & Get Hired\nWelcome to your smart AI assistant for study and skill-based jobs. π")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
mode = gr.Radio(["Study Help", "Job Finder"], label="Select Mode", value="Study Help")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
user_input = gr.Textbox(label="Ask StudyMate AI", placeholder="e.g., How can I improve my English speaking?")
|
| 38 |
+
|
| 39 |
+
output = gr.Textbox(label="AI Response", lines=10)
|
| 40 |
+
|
| 41 |
+
submit = gr.Button("Ask β¨")
|
| 42 |
+
submit.click(fn=chat_with_ai, inputs=[user_input, mode], outputs=output)
|
| 43 |
+
|
| 44 |
+
gr.Markdown("### πΉ Features Coming Soon\n- Post jobs directly inside StudyMate\n- Real-time student community help\n- Urdu/Sindhi language support\n\nπ¬ *Developed by Jawad*")
|
| 45 |
+
|
| 46 |
+
demo.launch()
|