dfdfdsfgs commited on
Commit
e32ff65
Β·
1 Parent(s): 9e31e8e

EXPLICIT HF Spaces Fix: More robust interface definition, explicit exports, better error handling

Browse files
Files changed (1) hide show
  1. app.py +68 -38
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 demo_function(topic, context="", max_scenes=3):
10
- """Generate demo educational content."""
11
  if not topic.strip():
12
  return "❌ Please enter a topic to explain"
13
 
14
- return f"""πŸŽ“ **Theorem Explanation Agent - Demo Mode**
15
 
16
- **Topic:** {topic}
17
- **Context:** {context if context else "None provided"}
18
- **Max Scenes:** {max_scenes}
19
 
20
- **βœ… Demo Generation Complete!**
21
 
22
- πŸ“Š **Simulated Results:**
23
- - ✨ Generated {max_scenes} educational scenes
24
- - 🎬 Total video duration: ~2.5 minutes
25
- - 🎯 Explanation type: Interactive mathematical proof
 
 
 
26
 
27
- **πŸ“ Educational Content:**
28
- 1. Introduction to {topic}
29
- 2. Core concepts and definitions
30
- 3. Step-by-step explanation
31
- 4. Real-world applications
32
- 5. Summary and key takeaways
33
 
34
- **⚠️ Demo Mode:** This is a simulation. In production, actual Manim videos would be generated.
 
 
35
 
36
- **πŸš€ To enable full functionality:** Set up API keys and install dependencies.
 
 
 
 
 
37
  """
 
38
 
39
- # Create simple interface
40
- demo = gr.Interface(
41
- fn=demo_function,
42
  inputs=[
43
- gr.Textbox(label="🎯 Topic to Explain", placeholder="Enter topic (e.g., 'Pythagorean Theorem')"),
44
- gr.Textbox(label="πŸ“‹ Context (Optional)", placeholder="Additional context or requirements"),
45
- gr.Slider(label="🎬 Number of Scenes", minimum=1, maximum=5, value=3, step=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ],
47
- outputs=gr.Textbox(label="πŸ“Š Generation Output", lines=15),
 
 
 
 
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", 3],
52
- ["Derivatives", "Focus on geometric interpretation", 4],
53
- ["Newton's Laws", "Include practical examples", 3]
54
- ]
 
 
 
 
55
  )
56
 
57
- # Launch the interface if run directly
 
 
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()