Turbiling commited on
Commit
cc886cc
·
verified ·
1 Parent(s): 20f02d5

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -203
app.py DELETED
@@ -1,203 +0,0 @@
1
- import gradio as gr
2
- from groq import Groq
3
- from docx import Document
4
- import datetime
5
- import os
6
-
7
- # ✅ Initialize Groq Client
8
- client = Groq(api_key="YOUR_GROQ_API_KEY")
9
-
10
- # ================== Helper Functions ==================
11
-
12
- def generate_text(prompt, model_name):
13
- response = client.chat.completions.create(
14
- messages=[{"role": "user", "content": prompt}],
15
- model=model_name,
16
- )
17
- return response.choices[0].message.content.strip()
18
-
19
- def save_docx(content, filename):
20
- doc = Document()
21
- doc.add_paragraph(content)
22
- filepath = f"/tmp/{filename}.docx"
23
- doc.save(filepath)
24
- return filepath
25
-
26
- def save_md(content, filename):
27
- content = content.replace("✨", "").replace("🌟", "").replace("✅", "")
28
- filepath = f"/tmp/{filename}.md"
29
- with open(filepath, "w", encoding="utf-8") as f:
30
- f.write(content)
31
- return filepath
32
-
33
- # ================== Core Generation Functions ==================
34
-
35
- def generate_lesson_plan(language, grade, subject, num_students, date, slo, content):
36
- if language == "English":
37
- model = "llama-3.1-8b-instant"
38
- prompt = f"""
39
- Create a SMART Lesson Plan in English for:
40
- Grade: {grade}
41
- Subject: {subject}
42
- Number of Students: {num_students}
43
- Date: {date}
44
-
45
- Include the following sections:
46
- 1. Input Table
47
- 2. SLOs
48
- 3. Content to be Delivered
49
- 4. Home Assignment (aligned with SLOs)
50
- 5. Feedback by Mentor/Principal
51
-
52
- Use this context:
53
- - SLOs: {slo}
54
- - Content: {content}
55
- """
56
- else:
57
- model = "openai/gpt-oss-120b"
58
- prompt = f"""
59
- درج ذیل معلومات کی بنیاد پر ایک SMART سبق کا منصوبہ اردو میں تیار کریں۔
60
- جماعت: {grade}
61
- مضمون: {subject}
62
- طلبہ کی تعداد: {num_students}
63
- تاریخ: {date}
64
-
65
- درج ذیل حصے شامل ہوں:
66
- 1. ان پٹ جدول
67
- 2. سیکھنے کے مقاصد (SLOs)
68
- 3. پڑھائی جانے والا مواد
69
- 4. گھریلو مشق (جو SLOs سے ہم آہنگ ہو)
70
- 5. سرپرست / پرنسپل کی رائے
71
-
72
- سیاق و سباق:
73
- - سیکھنے کے مقاصد: {slo}
74
- - مواد: {content}
75
- """
76
-
77
- output = generate_text(prompt, model)
78
- filename = f"SMART_Lesson_Plan_{language}_{grade}_{subject}"
79
- if language == "English":
80
- filepath = save_docx(output, filename)
81
- else:
82
- filepath = save_md(output, filename)
83
- return output, filepath
84
-
85
-
86
- def generate_flashcards(language, grade, subject, slo, content):
87
- if language == "English":
88
- model = "llama-3.1-8b-instant"
89
- prompt = f"""
90
- Create concise classroom flashcards in English for Grade {grade}, Subject {subject}.
91
- Align flashcards with the following SLOs and lesson content:
92
- SLOs: {slo}
93
- Content: {content}
94
- Format as Q&A flashcards.
95
- """
96
- else:
97
- model = "openai/gpt-oss-120b"
98
- prompt = f"""
99
- درج ذیل سیکھنے کے مقاصد اور مواد کی بنیاد پر جماعت {grade} کے لیے فلیش کارڈز تیار کریں۔
100
- مضمون: {subject}
101
- ہر کارڈ میں سوال اور مختصر جواب شامل ہو۔
102
- سیکھنے کے مقاصد: {slo}
103
- مواد: {content}
104
- """
105
-
106
- output = generate_text(prompt, model)
107
- filename = f"Flashcards_{language}_{grade}_{subject}"
108
- if language == "English":
109
- filepath = save_docx(output, filename)
110
- else:
111
- filepath = save_md(output, filename)
112
- return output, filepath
113
-
114
-
115
- def generate_quiz(language, grade, subject, slo, content):
116
- if language == "English":
117
- model = "llama-3.1-8b-instant"
118
- prompt = f"""
119
- Create a short quiz in English for Grade {grade}, Subject {subject}.
120
- Align questions with the following SLOs and lesson content.
121
- SLOs: {slo}
122
- Content: {content}
123
- Include 5 multiple-choice questions with answers.
124
- """
125
- else:
126
- model = "openai/gpt-oss-120b"
127
- prompt = f"""
128
- جماعت {grade}، مضمون {subject} کے لیے ایک مختصر کوئز اردو میں تیار کریں۔
129
- کوئز کے سوالات درج ذیل سیکھنے کے مقاصد اور مواد سے ہم آہنگ ہوں۔
130
- سیکھنے کے مقاصد: {slo}
131
- مواد: {content}
132
- پانچ کثیرالاختیاری سوالات (MCQs) شامل کریں اور جوابات بھی دیں۔
133
- """
134
-
135
- output = generate_text(prompt, model)
136
- filename = f"Quiz_{language}_{grade}_{subject}"
137
- if language == "English":
138
- filepath = save_docx(output, filename)
139
- else:
140
- filepath = save_md(output, filename)
141
- return output, filepath
142
-
143
-
144
- # ================== Gradio App ==================
145
-
146
- def main_app(language, feature, grade, subject, num_students, date, slo, content):
147
- if feature == "Lesson Plan":
148
- result, file = generate_lesson_plan(language, grade, subject, num_students, date, slo, content)
149
- return result, file, None, None
150
-
151
- elif feature == "Flashcards":
152
- result, file = generate_flashcards(language, grade, subject, slo, content)
153
- return result, None, file, None
154
-
155
- elif feature == "Quiz":
156
- result, file = generate_quiz(language, grade, subject, slo, content)
157
- return result, None, None, file
158
-
159
- else:
160
- return "Please select a valid feature.", None, None, None
161
-
162
-
163
- # ================== UI Layout ==================
164
-
165
- with gr.Blocks(title="SMART Lesson Plan Generator") as app:
166
- gr.Markdown("<h1 style='text-align:center;'>📘 SMART LESSON PLAN GENERATOR</h1>")
167
-
168
- with gr.Row():
169
- language = gr.Dropdown(["English", "Urdu"], label="Select Language", value="English")
170
- feature = gr.Dropdown(["Lesson Plan", "Flashcards", "Quiz"], label="Select Feature", value="Lesson Plan")
171
-
172
- with gr.Row():
173
- grade = gr.Dropdown(
174
- ["Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5", "Grade 6",
175
- "Grade 7", "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12"],
176
- label="Select Class/Grade"
177
- )
178
- subject = gr.Dropdown(
179
- ["English", "Urdu", "Mathematics", "Science", "Islamiyat", "Social Studies", "Computer Science"],
180
- label="Select Subject"
181
- )
182
-
183
- with gr.Row():
184
- num_students = gr.Number(label="Number of Students", value=30)
185
- date = gr.Textbox(label="Date (YYYY-MM-DD)", value=str(datetime.date.today()))
186
-
187
- slo = gr.Textbox(label="Enter SLOs (Learning Outcomes)", lines=3)
188
- content = gr.Textbox(label="Enter Lesson Content Summary", lines=3)
189
-
190
- generate_btn = gr.Button("🚀 Generate")
191
- output_text = gr.Textbox(label="Generated Output", lines=20)
192
-
193
- lesson_plan_file = gr.File(label="📄 Download Lesson Plan")
194
- flashcard_file = gr.File(label="📘 Download Flashcards")
195
- quiz_file = gr.File(label="🧾 Download Quiz")
196
-
197
- generate_btn.click(
198
- main_app,
199
- inputs=[language, feature, grade, subject, num_students, date, slo, content],
200
- outputs=[output_text, lesson_plan_file, flashcard_file, quiz_file]
201
- )
202
-
203
- app.launch()