Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import io
|
|
6 |
import json
|
7 |
import time
|
8 |
from typing import List, Dict, Any
|
|
|
9 |
|
10 |
class EducationalContentCreator:
|
11 |
def __init__(self):
|
@@ -47,6 +48,7 @@ class EducationalContentCreator:
|
|
47 |
except Exception as e:
|
48 |
return f"Error reading DOCX: {str(e)}"
|
49 |
|
|
|
50 |
def process_document(self, file):
|
51 |
"""Process uploaded document and extract text"""
|
52 |
if file is None:
|
@@ -68,6 +70,7 @@ class EducationalContentCreator:
|
|
68 |
else:
|
69 |
return "❌ Could not extract text from the document"
|
70 |
|
|
|
71 |
def generate_content(self, prompt: str, max_tokens: int = 2000) -> str:
|
72 |
"""Generate content using the AI model"""
|
73 |
if not self.client:
|
@@ -100,6 +103,7 @@ class EducationalContentCreator:
|
|
100 |
except Exception as e:
|
101 |
return f"❌ Error generating content: {str(e)}"
|
102 |
|
|
|
103 |
def generate_summary(self):
|
104 |
"""Generate comprehensive summary"""
|
105 |
prompt = """Create a comprehensive summary of this document with the following structure:
|
@@ -118,6 +122,7 @@ class EducationalContentCreator:
|
|
118 |
"""
|
119 |
return self.generate_content(prompt)
|
120 |
|
|
|
121 |
def generate_study_notes(self):
|
122 |
"""Generate structured study notes"""
|
123 |
prompt = """Create comprehensive study notes from this document with:
|
@@ -145,6 +150,7 @@ class EducationalContentCreator:
|
|
145 |
"""
|
146 |
return self.generate_content(prompt)
|
147 |
|
|
|
148 |
def generate_quiz(self):
|
149 |
"""Generate quiz questions"""
|
150 |
prompt = """Create a comprehensive quiz based on this document:
|
@@ -171,6 +177,7 @@ class EducationalContentCreator:
|
|
171 |
"""
|
172 |
return self.generate_content(prompt, max_tokens=3000)
|
173 |
|
|
|
174 |
def generate_flashcards(self):
|
175 |
"""Generate flashcards"""
|
176 |
prompt = """Create 15-20 flashcards based on this document:
|
@@ -193,6 +200,7 @@ class EducationalContentCreator:
|
|
193 |
"""
|
194 |
return self.generate_content(prompt, max_tokens=2500)
|
195 |
|
|
|
196 |
def generate_mind_map(self):
|
197 |
"""Generate mind map structure"""
|
198 |
prompt = """Create a detailed mind map structure for this document:
|
@@ -223,6 +231,7 @@ class EducationalContentCreator:
|
|
223 |
"""
|
224 |
return self.generate_content(prompt)
|
225 |
|
|
|
226 |
def generate_lesson_plan(self):
|
227 |
"""Generate lesson plan"""
|
228 |
prompt = """Create a detailed lesson plan based on this document:
|
@@ -267,6 +276,7 @@ class EducationalContentCreator:
|
|
267 |
"""
|
268 |
return self.generate_content(prompt, max_tokens=2500)
|
269 |
|
|
|
270 |
def generate_concept_explanations(self):
|
271 |
"""Generate detailed concept explanations"""
|
272 |
prompt = """Provide detailed explanations of key concepts from this document:
|
@@ -296,6 +306,7 @@ class EducationalContentCreator:
|
|
296 |
"""
|
297 |
return self.generate_content(prompt, max_tokens=3000)
|
298 |
|
|
|
299 |
def generate_practice_problems(self):
|
300 |
"""Generate practice problems"""
|
301 |
prompt = """Create practice problems based on this document:
|
@@ -341,6 +352,8 @@ def create_interface():
|
|
341 |
Transform your documents into comprehensive educational materials using AI!
|
342 |
|
343 |
**Features:** Study Notes • Quizzes • Flashcards • Mind Maps • Lesson Plans • Practice Problems & More!
|
|
|
|
|
344 |
""")
|
345 |
|
346 |
with gr.Row():
|
@@ -404,6 +417,9 @@ def create_interface():
|
|
404 |
- **Lesson Plan:** Complete teaching plan with objectives and activities
|
405 |
- **Concept Explanations:** Deep dive into key concepts with examples
|
406 |
- **Practice Problems:** Graded exercises from beginner to advanced
|
|
|
|
|
|
|
407 |
""")
|
408 |
|
409 |
# Event handlers
|
@@ -464,9 +480,4 @@ def create_interface():
|
|
464 |
# Launch the application
|
465 |
if __name__ == "__main__":
|
466 |
app = create_interface()
|
467 |
-
app.launch(
|
468 |
-
server_name="0.0.0.0",
|
469 |
-
server_port=7860,
|
470 |
-
share=True,
|
471 |
-
show_error=True
|
472 |
-
)
|
|
|
6 |
import json
|
7 |
import time
|
8 |
from typing import List, Dict, Any
|
9 |
+
import spaces
|
10 |
|
11 |
class EducationalContentCreator:
|
12 |
def __init__(self):
|
|
|
48 |
except Exception as e:
|
49 |
return f"Error reading DOCX: {str(e)}"
|
50 |
|
51 |
+
@spaces.GPU
|
52 |
def process_document(self, file):
|
53 |
"""Process uploaded document and extract text"""
|
54 |
if file is None:
|
|
|
70 |
else:
|
71 |
return "❌ Could not extract text from the document"
|
72 |
|
73 |
+
@spaces.GPU
|
74 |
def generate_content(self, prompt: str, max_tokens: int = 2000) -> str:
|
75 |
"""Generate content using the AI model"""
|
76 |
if not self.client:
|
|
|
103 |
except Exception as e:
|
104 |
return f"❌ Error generating content: {str(e)}"
|
105 |
|
106 |
+
@spaces.GPU
|
107 |
def generate_summary(self):
|
108 |
"""Generate comprehensive summary"""
|
109 |
prompt = """Create a comprehensive summary of this document with the following structure:
|
|
|
122 |
"""
|
123 |
return self.generate_content(prompt)
|
124 |
|
125 |
+
@spaces.GPU
|
126 |
def generate_study_notes(self):
|
127 |
"""Generate structured study notes"""
|
128 |
prompt = """Create comprehensive study notes from this document with:
|
|
|
150 |
"""
|
151 |
return self.generate_content(prompt)
|
152 |
|
153 |
+
@spaces.GPU
|
154 |
def generate_quiz(self):
|
155 |
"""Generate quiz questions"""
|
156 |
prompt = """Create a comprehensive quiz based on this document:
|
|
|
177 |
"""
|
178 |
return self.generate_content(prompt, max_tokens=3000)
|
179 |
|
180 |
+
@spaces.GPU
|
181 |
def generate_flashcards(self):
|
182 |
"""Generate flashcards"""
|
183 |
prompt = """Create 15-20 flashcards based on this document:
|
|
|
200 |
"""
|
201 |
return self.generate_content(prompt, max_tokens=2500)
|
202 |
|
203 |
+
@spaces.GPU
|
204 |
def generate_mind_map(self):
|
205 |
"""Generate mind map structure"""
|
206 |
prompt = """Create a detailed mind map structure for this document:
|
|
|
231 |
"""
|
232 |
return self.generate_content(prompt)
|
233 |
|
234 |
+
@spaces.GPU
|
235 |
def generate_lesson_plan(self):
|
236 |
"""Generate lesson plan"""
|
237 |
prompt = """Create a detailed lesson plan based on this document:
|
|
|
276 |
"""
|
277 |
return self.generate_content(prompt, max_tokens=2500)
|
278 |
|
279 |
+
@spaces.GPU
|
280 |
def generate_concept_explanations(self):
|
281 |
"""Generate detailed concept explanations"""
|
282 |
prompt = """Provide detailed explanations of key concepts from this 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:
|
|
|
352 |
Transform your documents into comprehensive educational materials using AI!
|
353 |
|
354 |
**Features:** Study Notes • Quizzes • Flashcards • Mind Maps • Lesson Plans • Practice Problems & More!
|
355 |
+
|
356 |
+
*Powered by ZeroGPU for enhanced performance*
|
357 |
""")
|
358 |
|
359 |
with gr.Row():
|
|
|
417 |
- **Lesson Plan:** Complete teaching plan with objectives and activities
|
418 |
- **Concept Explanations:** Deep dive into key concepts with examples
|
419 |
- **Practice Problems:** Graded exercises from beginner to advanced
|
420 |
+
|
421 |
+
### ⚡ Performance Note:
|
422 |
+
This app uses ZeroGPU for enhanced processing. Functions will automatically utilize GPU resources when needed.
|
423 |
""")
|
424 |
|
425 |
# Event handlers
|
|
|
480 |
# Launch the application
|
481 |
if __name__ == "__main__":
|
482 |
app = create_interface()
|
483 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|