Kubratech3 commited on
Commit
0cef3b8
Β·
verified Β·
1 Parent(s): 89b7d56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +177 -0
app.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+
6
+ # =========================
7
+ # Load API Key
8
+ # =========================
9
+ api_key = os.getenv("GROQ_API_KEY")
10
+
11
+ if not api_key:
12
+ raise ValueError("❌ GROQ_API_KEY not found. Add it in HF Secrets.")
13
+
14
+ client = Groq(api_key=api_key)
15
+
16
+
17
+ # =========================
18
+ # Generate Roadmap
19
+ # =========================
20
+ def generate_roadmap(domain, level, time):
21
+
22
+ if not domain or not time:
23
+ return "❌ Please fill all fields."
24
+
25
+ prompt = f"""
26
+ Create a detailed learning roadmap.
27
+
28
+ Domain: {domain}
29
+ Skill Level: {level}
30
+ Time Available: {time}
31
+
32
+ Include:
33
+ - Weekly plan
34
+ - Resources
35
+ - Projects
36
+ - Tips
37
+ """
38
+
39
+ try:
40
+ response = client.chat.completions.create(
41
+
42
+ model="llama-3.1-8b-instant",
43
+
44
+ messages=[
45
+ {"role": "system", "content": "You are an expert mentor."},
46
+ {"role": "user", "content": prompt}
47
+ ],
48
+
49
+ max_tokens=3000,
50
+ temperature=0.7
51
+ )
52
+
53
+ return response.choices[0].message.content
54
+
55
+ except Exception as e:
56
+ return f"❌ Error: {e}"
57
+
58
+
59
+ # =========================
60
+ # Custom CSS
61
+ # =========================
62
+ custom_css = """
63
+
64
+ html, body {
65
+ margin: 0;
66
+ padding: 0;
67
+ font-family: Arial, sans-serif;
68
+ }
69
+
70
+
71
+ /* Light Mode */
72
+ @media (prefers-color-scheme: light) {
73
+
74
+ html,
75
+ body,
76
+ .gradio-container,
77
+ .app,
78
+ .wrap,
79
+ .container {
80
+ background: linear-gradient(to right, #dff5e3, #b7e4c7) !important;
81
+ color: #1a1a1a !important;
82
+ }
83
+
84
+ input,
85
+ textarea,
86
+ select {
87
+ background: #f6fff8 !important;
88
+ color: #1a1a1a !important;
89
+ border: 1px solid #9dd9b1 !important;
90
+ border-radius: 6px;
91
+ }
92
+
93
+ button {
94
+ background: #6fcf97 !important;
95
+ color: #103822 !important;
96
+ border-radius: 8px !important;
97
+ font-weight: 600;
98
+ }
99
+
100
+ button:hover {
101
+ background: #5bbd84 !important;
102
+ }
103
+ }
104
+
105
+
106
+ /* Dark Mode */
107
+ @media (prefers-color-scheme: dark) {
108
+
109
+ html,
110
+ body,
111
+ .gradio-container,
112
+ .app,
113
+ .wrap,
114
+ .container {
115
+ background: linear-gradient(to right, #667eea, #764ba2) !important;
116
+ color: #ffffff !important;
117
+ }
118
+
119
+ input,
120
+ textarea,
121
+ select {
122
+ background: #1e1e2f !important;
123
+ color: #ffffff !important;
124
+ border: 1px solid #444 !important;
125
+ }
126
+
127
+ button {
128
+ background: #7c83fd !important;
129
+ color: white !important;
130
+ border-radius: 8px !important;
131
+ font-weight: 600;
132
+ }
133
+
134
+ button:hover {
135
+ background: #6a70e0 !important;
136
+ }
137
+ }
138
+
139
+ """
140
+
141
+
142
+ # =========================
143
+ # UI
144
+ # =========================
145
+ with gr.Blocks(css=custom_css) as app:
146
+
147
+ gr.Markdown(
148
+ """
149
+ # πŸ“˜ AI Learning Roadmap Generator πŸš€
150
+ Generate a personalized learning roadmap in seconds.
151
+ """
152
+ )
153
+
154
+ with gr.Row():
155
+ domain = gr.Textbox(label="πŸ“š Domain / Field")
156
+ level = gr.Dropdown(
157
+ ["Beginner", "Intermediate", "Advanced"],
158
+ label="🎯 Skill Level"
159
+ )
160
+
161
+ time = gr.Textbox(label="⏳ Time to Learn (e.g. 3 Months)")
162
+
163
+ generate_btn = gr.Button("✨ Generate Roadmap")
164
+
165
+ output = gr.Markdown()
166
+
167
+ generate_btn.click(
168
+ generate_roadmap,
169
+ inputs=[domain, level, time],
170
+ outputs=output
171
+ )
172
+
173
+
174
+ # =========================
175
+ # Launch
176
+ # =========================
177
+ app.launch(server_name="0.0.0.0", server_port=7860)