Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,69 +2,76 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
api_key = os.getenv("AI_Learning")
|
| 7 |
|
| 8 |
if not api_key:
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
client = Groq(api_key=api_key)
|
| 12 |
|
| 13 |
-
# Function to generate roadmap
|
| 14 |
def generate_roadmap(domain, level, duration):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
gr.Markdown(""
|
| 50 |
-
# 🚀 AI Learning Roadmap Generator
|
| 51 |
-
Generate a personalized learning roadmap using AI.
|
| 52 |
-
""")
|
| 53 |
|
| 54 |
-
domain = gr.Textbox(label="Domain / Field", placeholder="e.g.
|
| 55 |
level = gr.Dropdown(
|
| 56 |
-
|
| 57 |
-
label="Skill Level"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
)
|
| 59 |
-
duration = gr.Textbox(label="Time to Learn", placeholder="e.g. 3 months, 6 months")
|
| 60 |
|
| 61 |
-
|
| 62 |
output = gr.Markdown()
|
| 63 |
|
| 64 |
-
|
| 65 |
-
fn=generate_roadmap,
|
| 66 |
-
inputs=[domain, level, duration],
|
| 67 |
-
outputs=output
|
| 68 |
-
)
|
| 69 |
|
| 70 |
app.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
+
# Load API key
|
| 6 |
api_key = os.getenv("AI_Learning")
|
| 7 |
|
| 8 |
if not api_key:
|
| 9 |
+
with gr.Blocks() as app:
|
| 10 |
+
gr.Markdown("## ❌ Configuration Error")
|
| 11 |
+
gr.Markdown("Groq API key not found. Add it in **Settings → Secrets** as `AI_Learning`.")
|
| 12 |
+
app.launch()
|
| 13 |
+
exit()
|
| 14 |
|
| 15 |
client = Groq(api_key=api_key)
|
| 16 |
|
|
|
|
| 17 |
def generate_roadmap(domain, level, duration):
|
| 18 |
+
try:
|
| 19 |
+
if not domain or not duration:
|
| 20 |
+
return "⚠️ Please fill all fields."
|
| 21 |
+
|
| 22 |
+
prompt = f"""
|
| 23 |
+
You are an expert mentor.
|
| 24 |
+
|
| 25 |
+
Create a detailed learning roadmap.
|
| 26 |
+
|
| 27 |
+
Domain: {domain}
|
| 28 |
+
Skill level: {level}
|
| 29 |
+
Learning duration: {duration}
|
| 30 |
+
|
| 31 |
+
Include:
|
| 32 |
+
- Weekly plan
|
| 33 |
+
- Topics to learn
|
| 34 |
+
- Tools & technologies
|
| 35 |
+
- Free resources
|
| 36 |
+
- Practice projects
|
| 37 |
+
|
| 38 |
+
Make it clear and beginner friendly.
|
| 39 |
"""
|
| 40 |
|
| 41 |
+
response = client.chat.completions.create(
|
| 42 |
+
model="llama-3.1-8b-instant", # safer & faster
|
| 43 |
+
messages=[
|
| 44 |
+
{"role": "system", "content": "You create structured learning roadmaps."},
|
| 45 |
+
{"role": "user", "content": prompt}
|
| 46 |
+
],
|
| 47 |
+
temperature=0.6,
|
| 48 |
+
max_tokens=1000
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
return response.choices[0].message.content
|
| 52 |
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return f"❌ Error occurred:\n\n{str(e)}"
|
| 55 |
|
| 56 |
|
| 57 |
+
with gr.Blocks() as app:
|
| 58 |
+
gr.Markdown("# 🚀 AI Learning Roadmap Generator")
|
| 59 |
+
gr.Markdown("Generate a personalized learning roadmap using AI.")
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
domain = gr.Textbox(label="Domain / Field", placeholder="e.g. Web Development")
|
| 62 |
level = gr.Dropdown(
|
| 63 |
+
["Beginner", "Intermediate", "Advanced"],
|
| 64 |
+
label="Skill Level",
|
| 65 |
+
value="Beginner"
|
| 66 |
+
)
|
| 67 |
+
duration = gr.Textbox(
|
| 68 |
+
label="Time to Learn",
|
| 69 |
+
placeholder="e.g. 3 months, 6 months"
|
| 70 |
)
|
|
|
|
| 71 |
|
| 72 |
+
btn = gr.Button("Generate Roadmap")
|
| 73 |
output = gr.Markdown()
|
| 74 |
|
| 75 |
+
btn.click(generate_roadmap, inputs=[domain, level, duration], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
app.launch()
|