Spaces:
Sleeping
Sleeping
EXPLICIT HF Spaces Fix: More robust interface definition, explicit exports, better error handling
Browse files
app.py
CHANGED
|
@@ -6,59 +6,89 @@ A web interface for generating educational videos explaining mathematical theore
|
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
"""Generate
|
| 11 |
if not topic.strip():
|
| 12 |
return "β Please enter a topic to explain"
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
**Topic:** {topic}
|
| 17 |
-
**Context:** {context if context else "None
|
| 18 |
-
**
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
5. Summary and key takeaways
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
"""
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
fn=
|
| 42 |
inputs=[
|
| 43 |
-
gr.Textbox(
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
],
|
| 47 |
-
outputs=gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
title="π Theorem Explanation Agent",
|
| 49 |
-
description="Generate educational videos explaining mathematical theorems and concepts using AI",
|
| 50 |
examples=[
|
| 51 |
-
["Pythagorean Theorem", "Include visual proof",
|
| 52 |
-
["Derivatives", "Focus on geometric interpretation",
|
| 53 |
-
["Newton's Laws", "
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
-
#
|
|
|
|
|
|
|
| 58 |
if __name__ == "__main__":
|
| 59 |
-
demo.launch(
|
| 60 |
-
server_name="0.0.0.0",
|
| 61 |
-
server_port=7860,
|
| 62 |
-
share=False,
|
| 63 |
-
show_error=True
|
| 64 |
-
)
|
|
|
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
+
def generate_explanation(topic, context, max_scenes):
|
| 10 |
+
"""Generate educational content explanation."""
|
| 11 |
if not topic.strip():
|
| 12 |
return "β Please enter a topic to explain"
|
| 13 |
|
| 14 |
+
result = f"""π **Theorem Explanation Agent**
|
| 15 |
|
| 16 |
+
π **Topic:** {topic}
|
| 17 |
+
π **Context:** {context if context else "None specified"}
|
| 18 |
+
π¬ **Scenes:** {max_scenes}
|
| 19 |
|
| 20 |
+
β
**Demo Generation Complete!**
|
| 21 |
|
| 22 |
+
π― **Generated Educational Content:**
|
| 23 |
+
β’ Introduction to {topic}
|
| 24 |
+
β’ Fundamental concepts and definitions
|
| 25 |
+
β’ Step-by-step mathematical derivation
|
| 26 |
+
β’ Visual demonstrations and proofs
|
| 27 |
+
β’ Real-world applications and examples
|
| 28 |
+
β’ Practice problems and solutions
|
| 29 |
|
| 30 |
+
π **Video Specifications:**
|
| 31 |
+
β’ Duration: ~{max_scenes * 0.8:.1f} minutes
|
| 32 |
+
β’ Scene count: {max_scenes}
|
| 33 |
+
β’ Style: Mathematical animations
|
| 34 |
+
β’ Voiceover: AI-generated narration
|
|
|
|
| 35 |
|
| 36 |
+
β οΈ **Demo Mode Active**
|
| 37 |
+
This is a simulation showing the interface capabilities.
|
| 38 |
+
In production mode, actual Manim animations would be generated.
|
| 39 |
|
| 40 |
+
π **Production Features:**
|
| 41 |
+
β Manim mathematical animations
|
| 42 |
+
β AI-powered script generation
|
| 43 |
+
β Professional voiceover synthesis
|
| 44 |
+
β Multiple output formats
|
| 45 |
+
β Custom styling and branding
|
| 46 |
"""
|
| 47 |
+
return result
|
| 48 |
|
| 49 |
+
# Define the interface explicitly
|
| 50 |
+
iface = gr.Interface(
|
| 51 |
+
fn=generate_explanation,
|
| 52 |
inputs=[
|
| 53 |
+
gr.Textbox(
|
| 54 |
+
label="π― Mathematical Topic",
|
| 55 |
+
placeholder="Enter any mathematical concept (e.g., Pythagorean Theorem, Derivatives, etc.)",
|
| 56 |
+
value=""
|
| 57 |
+
),
|
| 58 |
+
gr.Textbox(
|
| 59 |
+
label="π Additional Context",
|
| 60 |
+
placeholder="Specify learning level, focus areas, or special requirements (optional)",
|
| 61 |
+
value=""
|
| 62 |
+
),
|
| 63 |
+
gr.Slider(
|
| 64 |
+
label="π¬ Number of Video Scenes",
|
| 65 |
+
minimum=1,
|
| 66 |
+
maximum=8,
|
| 67 |
+
value=4,
|
| 68 |
+
step=1,
|
| 69 |
+
info="More scenes = more detailed explanation"
|
| 70 |
+
)
|
| 71 |
],
|
| 72 |
+
outputs=gr.Textbox(
|
| 73 |
+
label="π Generated Educational Content",
|
| 74 |
+
lines=20,
|
| 75 |
+
show_copy_button=True
|
| 76 |
+
),
|
| 77 |
title="π Theorem Explanation Agent",
|
| 78 |
+
description="π Generate educational videos explaining mathematical theorems and concepts using AI-powered animations",
|
| 79 |
examples=[
|
| 80 |
+
["Pythagorean Theorem", "Include visual proof and real-world applications", 4],
|
| 81 |
+
["Calculus Derivatives", "Focus on geometric interpretation for beginners", 5],
|
| 82 |
+
["Newton's Laws of Motion", "Physics applications with practical examples", 3],
|
| 83 |
+
["Quadratic Formula", "Step-by-step derivation with examples", 4],
|
| 84 |
+
["Probability Distributions", "Visual explanations with real-world data", 5]
|
| 85 |
+
],
|
| 86 |
+
theme=gr.themes.Soft(),
|
| 87 |
+
css="footer {visibility: hidden}"
|
| 88 |
)
|
| 89 |
|
| 90 |
+
# Export for HF Spaces
|
| 91 |
+
demo = iface
|
| 92 |
+
|
| 93 |
if __name__ == "__main__":
|
| 94 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|