Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,344 +5,359 @@ from openai import OpenAI
|
|
5 |
import io
|
6 |
import json
|
7 |
import time
|
8 |
-
from typing import List, Dict, Any
|
9 |
import spaces
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
text = ""
|
45 |
-
for
|
46 |
-
text +=
|
47 |
return text
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
},
|
88 |
-
|
89 |
-
|
90 |
-
{
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
---
|
304 |
-
|
305 |
-
Repeat this structure for all major concepts in the document.
|
306 |
-
"""
|
307 |
-
return self.generate_content(prompt, max_tokens=3000)
|
308 |
-
|
309 |
-
@spaces.GPU
|
310 |
-
def generate_practice_problems(self):
|
311 |
-
"""Generate practice problems"""
|
312 |
-
prompt = """Create practice problems based on this document:
|
313 |
-
|
314 |
-
## πͺ Practice Problems
|
315 |
-
|
316 |
-
### Beginner Level (5 problems)
|
317 |
-
- Basic application of concepts
|
318 |
-
- Direct recall and simple calculations
|
319 |
-
- Step-by-step solutions provided
|
320 |
-
|
321 |
-
### Intermediate Level (5 problems)
|
322 |
-
- Multi-step problems
|
323 |
-
- Requires understanding of relationships
|
324 |
-
- Guided solutions with explanations
|
325 |
-
|
326 |
-
### Advanced Level (3 problems)
|
327 |
-
- Complex scenarios
|
328 |
-
- Requires analysis and synthesis
|
329 |
-
- Detailed solution strategies
|
330 |
-
|
331 |
-
### Challenge Problems (2 problems)
|
332 |
-
- Extension beyond document content
|
333 |
-
- Creative application
|
334 |
-
- Multiple solution approaches
|
335 |
-
|
336 |
-
**For each problem, include:**
|
337 |
-
- Clear problem statement
|
338 |
-
- Required formulas/concepts
|
339 |
-
- Step-by-step solution
|
340 |
-
- Common mistakes to avoid
|
341 |
-
"""
|
342 |
-
return self.generate_content(prompt, max_tokens=3500)
|
343 |
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
# Create Gradio interface
|
348 |
def create_interface():
|
@@ -424,54 +439,54 @@ def create_interface():
|
|
424 |
|
425 |
# Event handlers
|
426 |
setup_btn.click(
|
427 |
-
|
428 |
inputs=[api_key],
|
429 |
outputs=[setup_status]
|
430 |
)
|
431 |
|
432 |
process_btn.click(
|
433 |
-
|
434 |
inputs=[file_upload],
|
435 |
outputs=[process_status]
|
436 |
)
|
437 |
|
438 |
summary_btn.click(
|
439 |
-
|
440 |
outputs=[output]
|
441 |
)
|
442 |
|
443 |
notes_btn.click(
|
444 |
-
|
445 |
outputs=[output]
|
446 |
)
|
447 |
|
448 |
quiz_btn.click(
|
449 |
-
|
450 |
outputs=[output]
|
451 |
)
|
452 |
|
453 |
flashcards_btn.click(
|
454 |
-
|
455 |
outputs=[output]
|
456 |
)
|
457 |
|
458 |
mindmap_btn.click(
|
459 |
-
|
460 |
outputs=[output]
|
461 |
)
|
462 |
|
463 |
lesson_btn.click(
|
464 |
-
|
465 |
outputs=[output]
|
466 |
)
|
467 |
|
468 |
concepts_btn.click(
|
469 |
-
|
470 |
outputs=[output]
|
471 |
)
|
472 |
|
473 |
problems_btn.click(
|
474 |
-
|
475 |
outputs=[output]
|
476 |
)
|
477 |
|
|
|
5 |
import io
|
6 |
import json
|
7 |
import time
|
8 |
+
from typing import List, Dict, Any, Optional
|
9 |
import spaces
|
10 |
|
11 |
+
# Global variables to store API key and document text
|
12 |
+
API_KEY = ""
|
13 |
+
DOCUMENT_TEXT = ""
|
14 |
+
MODEL = "google/gemma-3-27b-it:free"
|
15 |
+
|
16 |
+
def setup_client(api_key: str):
|
17 |
+
"""Initialize and test API key"""
|
18 |
+
global API_KEY
|
19 |
+
try:
|
20 |
+
# Test the API key by creating a client and making a simple request
|
21 |
+
client = OpenAI(
|
22 |
+
base_url="https://openrouter.ai/api/v1",
|
23 |
+
api_key=api_key,
|
24 |
+
)
|
25 |
+
# Store the API key globally
|
26 |
+
API_KEY = api_key
|
27 |
+
return "β
API Key configured successfully!"
|
28 |
+
except Exception as e:
|
29 |
+
return f"β Error configuring API: {str(e)}"
|
30 |
+
|
31 |
+
def create_client() -> Optional[OpenAI]:
|
32 |
+
"""Create OpenAI client with stored API key"""
|
33 |
+
if not API_KEY:
|
34 |
+
return None
|
35 |
+
return OpenAI(
|
36 |
+
base_url="https://openrouter.ai/api/v1",
|
37 |
+
api_key=API_KEY,
|
38 |
+
)
|
39 |
+
|
40 |
+
def extract_text_from_pdf(file_path: str) -> str:
|
41 |
+
"""Extract text from PDF file"""
|
42 |
+
try:
|
43 |
+
with open(file_path, 'rb') as file:
|
44 |
+
pdf_reader = PyPDF2.PdfReader(file)
|
45 |
text = ""
|
46 |
+
for page in pdf_reader.pages:
|
47 |
+
text += page.extract_text() + "\n"
|
48 |
return text
|
49 |
+
except Exception as e:
|
50 |
+
return f"Error reading PDF: {str(e)}"
|
51 |
+
|
52 |
+
def extract_text_from_docx(file_path: str) -> str:
|
53 |
+
"""Extract text from DOCX file"""
|
54 |
+
try:
|
55 |
+
doc = docx.Document(file_path)
|
56 |
+
text = ""
|
57 |
+
for paragraph in doc.paragraphs:
|
58 |
+
text += paragraph.text + "\n"
|
59 |
+
return text
|
60 |
+
except Exception as e:
|
61 |
+
return f"Error reading DOCX: {str(e)}"
|
62 |
+
|
63 |
+
@spaces.GPU
|
64 |
+
def process_document(file):
|
65 |
+
"""Process uploaded document and extract text"""
|
66 |
+
global DOCUMENT_TEXT
|
67 |
+
|
68 |
+
if file is None:
|
69 |
+
return "β No file uploaded"
|
70 |
+
|
71 |
+
file_path = file.name
|
72 |
+
file_extension = file_path.lower().split('.')[-1]
|
73 |
+
|
74 |
+
if file_extension == 'pdf':
|
75 |
+
DOCUMENT_TEXT = extract_text_from_pdf(file_path)
|
76 |
+
elif file_extension in ['docx', 'doc']:
|
77 |
+
DOCUMENT_TEXT = extract_text_from_docx(file_path)
|
78 |
+
else:
|
79 |
+
return "β Unsupported file format. Please upload PDF or DOCX files."
|
80 |
+
|
81 |
+
if DOCUMENT_TEXT and len(DOCUMENT_TEXT.strip()) > 0:
|
82 |
+
word_count = len(DOCUMENT_TEXT.split())
|
83 |
+
return f"β
Document processed successfully!\nπ Word count: {word_count}\nπ Preview: {DOCUMENT_TEXT[:200]}..."
|
84 |
+
else:
|
85 |
+
return "β Could not extract text from the document"
|
86 |
+
|
87 |
+
@spaces.GPU
|
88 |
+
def generate_content(prompt: str, max_tokens: int = 2000) -> str:
|
89 |
+
"""Generate content using the AI model"""
|
90 |
+
if not API_KEY:
|
91 |
+
return "β Please configure your API key first"
|
92 |
+
|
93 |
+
if not DOCUMENT_TEXT:
|
94 |
+
return "β Please upload and process a document first"
|
95 |
+
|
96 |
+
try:
|
97 |
+
client = create_client()
|
98 |
+
if not client:
|
99 |
+
return "β Failed to create API client"
|
100 |
+
|
101 |
+
completion = client.chat.completions.create(
|
102 |
+
extra_headers={
|
103 |
+
"HTTP-Referer": "https://educational-assistant.app",
|
104 |
+
"X-Title": "Educational Content Creator",
|
105 |
+
},
|
106 |
+
model=MODEL,
|
107 |
+
messages=[
|
108 |
+
{
|
109 |
+
"role": "system",
|
110 |
+
"content": "You are an expert educational content creator. Create comprehensive, engaging, and pedagogically sound educational materials based on the provided document content."
|
111 |
},
|
112 |
+
{
|
113 |
+
"role": "user",
|
114 |
+
"content": f"Document Content:\n{DOCUMENT_TEXT}\n\n{prompt}"
|
115 |
+
}
|
116 |
+
],
|
117 |
+
max_tokens=max_tokens,
|
118 |
+
temperature=0.7
|
119 |
+
)
|
120 |
+
return completion.choices[0].message.content
|
121 |
+
except Exception as e:
|
122 |
+
return f"β Error generating content: {str(e)}"
|
123 |
+
|
124 |
+
@spaces.GPU
|
125 |
+
def generate_summary():
|
126 |
+
"""Generate comprehensive summary"""
|
127 |
+
prompt = """Create a comprehensive summary of this document with the following structure:
|
128 |
+
|
129 |
+
## π Executive Summary
|
130 |
+
Provide a brief overview in 2-3 sentences.
|
131 |
+
|
132 |
+
## π― Key Points
|
133 |
+
List the main concepts, ideas, or arguments presented.
|
134 |
+
|
135 |
+
## π Detailed Summary
|
136 |
+
Provide a thorough summary organized by topics or sections.
|
137 |
+
|
138 |
+
## π‘ Important Takeaways
|
139 |
+
Highlight the most crucial information students should remember.
|
140 |
+
"""
|
141 |
+
return generate_content(prompt)
|
142 |
+
|
143 |
+
@spaces.GPU
|
144 |
+
def generate_study_notes():
|
145 |
+
"""Generate structured study notes"""
|
146 |
+
prompt = """Create comprehensive study notes from this document with:
|
147 |
+
|
148 |
+
## π Study Notes
|
149 |
+
|
150 |
+
### π Key Concepts
|
151 |
+
- Define important terms and concepts
|
152 |
+
- Explain their significance
|
153 |
+
|
154 |
+
### π Main Topics
|
155 |
+
Organize content into clear sections with:
|
156 |
+
- Topic headings
|
157 |
+
- Key points under each topic
|
158 |
+
- Supporting details and examples
|
159 |
+
|
160 |
+
### π§ Memory Aids
|
161 |
+
- Create mnemonics for complex information
|
162 |
+
- Suggest visualization techniques
|
163 |
+
- Provide connection points between concepts
|
164 |
+
|
165 |
+
### β‘ Quick Review Points
|
166 |
+
- Bullet points for rapid review
|
167 |
+
- Essential facts and figures
|
168 |
+
"""
|
169 |
+
return generate_content(prompt)
|
170 |
+
|
171 |
+
@spaces.GPU
|
172 |
+
def generate_quiz():
|
173 |
+
"""Generate quiz questions"""
|
174 |
+
prompt = """Create a comprehensive quiz based on this document:
|
175 |
+
|
176 |
+
## π Quiz Questions
|
177 |
+
|
178 |
+
### Multiple Choice Questions (5 questions)
|
179 |
+
For each question, provide:
|
180 |
+
- Clear question
|
181 |
+
- 4 options (A, B, C, D)
|
182 |
+
- Correct answer
|
183 |
+
- Brief explanation
|
184 |
+
|
185 |
+
### Short Answer Questions (5 questions)
|
186 |
+
- Questions requiring 2-3 sentence answers
|
187 |
+
- Cover key concepts and applications
|
188 |
+
|
189 |
+
### Essay Questions (2 questions)
|
190 |
+
- Thought-provoking questions requiring detailed responses
|
191 |
+
- Focus on analysis, synthesis, or evaluation
|
192 |
+
|
193 |
+
### Answer Key
|
194 |
+
Provide all correct answers with explanations.
|
195 |
+
"""
|
196 |
+
return generate_content(prompt, max_tokens=3000)
|
197 |
+
|
198 |
+
@spaces.GPU
|
199 |
+
def generate_flashcards():
|
200 |
+
"""Generate flashcards"""
|
201 |
+
prompt = """Create 15-20 flashcards based on this document:
|
202 |
+
|
203 |
+
## π΄ Flashcards
|
204 |
+
|
205 |
+
Format each flashcard as:
|
206 |
+
**Card X:**
|
207 |
+
**Front:** [Question/Term]
|
208 |
+
**Back:** [Answer/Definition/Explanation]
|
209 |
+
|
210 |
+
Include flashcards for:
|
211 |
+
- Key terms and definitions
|
212 |
+
- Important concepts
|
213 |
+
- Facts and figures
|
214 |
+
- Cause and effect relationships
|
215 |
+
- Applications and examples
|
216 |
+
|
217 |
+
Make questions clear and answers comprehensive but concise.
|
218 |
+
"""
|
219 |
+
return generate_content(prompt, max_tokens=2500)
|
220 |
+
|
221 |
+
@spaces.GPU
|
222 |
+
def generate_mind_map():
|
223 |
+
"""Generate mind map structure"""
|
224 |
+
prompt = """Create a detailed mind map structure for this document:
|
225 |
+
|
226 |
+
## π§ Mind Map Structure
|
227 |
+
|
228 |
+
**Central Topic:** [Main subject of the document]
|
229 |
+
|
230 |
+
### Primary Branches:
|
231 |
+
For each main topic, create branches with:
|
232 |
+
- **Branch 1:** [Topic Name]
|
233 |
+
- Sub-branch 1.1: [Subtopic]
|
234 |
+
- Detail 1.1.1
|
235 |
+
- Detail 1.1.2
|
236 |
+
- Sub-branch 1.2: [Subtopic]
|
237 |
+
- Detail 1.2.1
|
238 |
+
- Detail 1.2.2
|
239 |
+
|
240 |
+
### Connections:
|
241 |
+
- Identify relationships between different branches
|
242 |
+
- Note cross-references and dependencies
|
243 |
+
- Highlight cause-effect relationships
|
244 |
+
|
245 |
+
### Visual Elements Suggestions:
|
246 |
+
- Color coding recommendations
|
247 |
+
- Symbol suggestions for different types of information
|
248 |
+
- Emphasis techniques for key concepts
|
249 |
+
"""
|
250 |
+
return generate_content(prompt)
|
251 |
+
|
252 |
+
@spaces.GPU
|
253 |
+
def generate_lesson_plan():
|
254 |
+
"""Generate lesson plan"""
|
255 |
+
prompt = """Create a detailed lesson plan based on this document:
|
256 |
+
|
257 |
+
## π Lesson Plan
|
258 |
+
|
259 |
+
### Learning Objectives
|
260 |
+
By the end of this lesson, students will be able to:
|
261 |
+
- [Specific, measurable objectives]
|
262 |
+
|
263 |
+
### Prerequisites
|
264 |
+
- Required background knowledge
|
265 |
+
- Recommended prior reading
|
266 |
+
|
267 |
+
### Lesson Structure (60 minutes)
|
268 |
+
|
269 |
+
**Introduction (10 minutes)**
|
270 |
+
- Hook/attention grabber
|
271 |
+
- Learning objectives overview
|
272 |
+
|
273 |
+
**Main Content (35 minutes)**
|
274 |
+
- Key concepts presentation
|
275 |
+
- Activities and examples
|
276 |
+
- Discussion points
|
277 |
+
|
278 |
+
**Practice & Application (10 minutes)**
|
279 |
+
- Practice exercises
|
280 |
+
- Real-world applications
|
281 |
+
|
282 |
+
**Wrap-up & Assessment (5 minutes)**
|
283 |
+
- Summary of key points
|
284 |
+
- Quick assessment questions
|
285 |
+
|
286 |
+
### Materials Needed
|
287 |
+
- List of required resources
|
288 |
+
|
289 |
+
### Assessment Methods
|
290 |
+
- How to evaluate student understanding
|
291 |
+
|
292 |
+
### Homework/Extension Activities
|
293 |
+
- Additional practice opportunities
|
294 |
+
"""
|
295 |
+
return generate_content(prompt, max_tokens=2500)
|
296 |
+
|
297 |
+
@spaces.GPU
|
298 |
+
def generate_concept_explanations():
|
299 |
+
"""Generate detailed concept explanations"""
|
300 |
+
prompt = """Provide detailed explanations of key concepts from this document:
|
301 |
+
|
302 |
+
## π Concept Deep Dive
|
303 |
+
|
304 |
+
For each major concept, provide:
|
305 |
+
|
306 |
+
### Concept Name
|
307 |
+
**Definition:** Clear, precise definition
|
308 |
+
|
309 |
+
**Explanation:** Detailed explanation in simple terms
|
310 |
+
|
311 |
+
**Examples:** Real-world examples and applications
|
312 |
+
|
313 |
+
**Analogies:** Helpful comparisons to familiar concepts
|
314 |
+
|
315 |
+
**Common Misconceptions:** What students often get wrong
|
316 |
+
|
317 |
+
**Connection to Other Concepts:** How it relates to other topics
|
318 |
+
|
319 |
+
**Practice Application:** Simple exercise or question
|
320 |
+
|
321 |
+
---
|
322 |
+
|
323 |
+
Repeat this structure for all major concepts in the document.
|
324 |
+
"""
|
325 |
+
return generate_content(prompt, max_tokens=3000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
|
327 |
+
@spaces.GPU
|
328 |
+
def generate_practice_problems():
|
329 |
+
"""Generate practice problems"""
|
330 |
+
prompt = """Create practice problems based on this document:
|
331 |
+
|
332 |
+
## πͺ Practice Problems
|
333 |
+
|
334 |
+
### Beginner Level (5 problems)
|
335 |
+
- Basic application of concepts
|
336 |
+
- Direct recall and simple calculations
|
337 |
+
- Step-by-step solutions provided
|
338 |
+
|
339 |
+
### Intermediate Level (5 problems)
|
340 |
+
- Multi-step problems
|
341 |
+
- Requires understanding of relationships
|
342 |
+
- Guided solutions with explanations
|
343 |
+
|
344 |
+
### Advanced Level (3 problems)
|
345 |
+
- Complex scenarios
|
346 |
+
- Requires analysis and synthesis
|
347 |
+
- Detailed solution strategies
|
348 |
+
|
349 |
+
### Challenge Problems (2 problems)
|
350 |
+
- Extension beyond document content
|
351 |
+
- Creative application
|
352 |
+
- Multiple solution approaches
|
353 |
+
|
354 |
+
**For each problem, include:**
|
355 |
+
- Clear problem statement
|
356 |
+
- Required formulas/concepts
|
357 |
+
- Step-by-step solution
|
358 |
+
- Common mistakes to avoid
|
359 |
+
"""
|
360 |
+
return generate_content(prompt, max_tokens=3500)
|
361 |
|
362 |
# Create Gradio interface
|
363 |
def create_interface():
|
|
|
439 |
|
440 |
# Event handlers
|
441 |
setup_btn.click(
|
442 |
+
setup_client,
|
443 |
inputs=[api_key],
|
444 |
outputs=[setup_status]
|
445 |
)
|
446 |
|
447 |
process_btn.click(
|
448 |
+
process_document,
|
449 |
inputs=[file_upload],
|
450 |
outputs=[process_status]
|
451 |
)
|
452 |
|
453 |
summary_btn.click(
|
454 |
+
generate_summary,
|
455 |
outputs=[output]
|
456 |
)
|
457 |
|
458 |
notes_btn.click(
|
459 |
+
generate_study_notes,
|
460 |
outputs=[output]
|
461 |
)
|
462 |
|
463 |
quiz_btn.click(
|
464 |
+
generate_quiz,
|
465 |
outputs=[output]
|
466 |
)
|
467 |
|
468 |
flashcards_btn.click(
|
469 |
+
generate_flashcards,
|
470 |
outputs=[output]
|
471 |
)
|
472 |
|
473 |
mindmap_btn.click(
|
474 |
+
generate_mind_map,
|
475 |
outputs=[output]
|
476 |
)
|
477 |
|
478 |
lesson_btn.click(
|
479 |
+
generate_lesson_plan,
|
480 |
outputs=[output]
|
481 |
)
|
482 |
|
483 |
concepts_btn.click(
|
484 |
+
generate_concept_explanations,
|
485 |
outputs=[output]
|
486 |
)
|
487 |
|
488 |
problems_btn.click(
|
489 |
+
generate_practice_problems,
|
490 |
outputs=[output]
|
491 |
)
|
492 |
|