jehanzada commited on
Commit
2b1ddc7
·
verified ·
1 Parent(s): b8e5894

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -46
app.py CHANGED
@@ -2,69 +2,76 @@ import os
2
  import gradio as gr
3
  from groq import Groq
4
 
5
- # Load Groq API key from Hugging Face secrets
6
  api_key = os.getenv("AI_Learning")
7
 
8
  if not api_key:
9
- raise ValueError("AI_Learning")
 
 
 
 
10
 
11
  client = Groq(api_key=api_key)
12
 
13
- # Function to generate roadmap
14
  def generate_roadmap(domain, level, duration):
15
- prompt = f"""
16
- You are an expert AI mentor.
17
-
18
- Create a detailed learning roadmap for:
19
- - Domain: {domain}
20
- - Skill Level: {level}
21
- - Time Duration: {duration}
22
-
23
- The roadmap should include:
24
- 1. Clear learning goals
25
- 2. Step-by-step topics
26
- 3. Weekly breakdown
27
- 4. Tools & technologies
28
- 5. Free learning resources
29
- 6. Practical project ideas
30
-
31
- Make it beginner friendly and structured.
 
 
 
 
32
  """
33
 
34
- response = client.chat.completions.create(
35
- model="llama-3.1-70b-versatile",
36
- messages=[
37
- {"role": "system", "content": "You are a professional AI learning roadmap generator."},
38
- {"role": "user", "content": prompt}
39
- ],
40
- temperature=0.7,
41
- max_tokens=1200
42
- )
 
 
43
 
44
- return response.choices[0].message.content
 
45
 
46
 
47
- # Gradio UI
48
- with gr.Blocks(title="AI Learning Roadmap Generator") as app:
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. Artificial Intelligence, Web Development")
55
  level = gr.Dropdown(
56
- choices=["Beginner", "Intermediate", "Advanced"],
57
- label="Skill Level"
 
 
 
 
 
58
  )
59
- duration = gr.Textbox(label="Time to Learn", placeholder="e.g. 3 months, 6 months")
60
 
61
- generate_btn = gr.Button("Generate Roadmap")
62
  output = gr.Markdown()
63
 
64
- generate_btn.click(
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()