Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,9 @@ class LearningPathGenerator:
|
|
15 |
|
16 |
def process_audio(self,
|
17 |
audio_path: str,
|
18 |
-
|
|
|
|
|
19 |
try:
|
20 |
# Transcribe audio
|
21 |
transcription = self.transcriber(audio_path)["text"]
|
@@ -33,36 +35,140 @@ class LearningPathGenerator:
|
|
33 |
max_length=300,
|
34 |
num_return_sequences=1)[0]["generated_text"]
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
except Exception as e:
|
41 |
-
return
|
42 |
-
|
43 |
-
"
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def create_interface():
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
gr.
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return app
|
65 |
|
66 |
if __name__ == "__main__":
|
67 |
app = create_interface()
|
|
|
68 |
app.launch()
|
|
|
15 |
|
16 |
def process_audio(self,
|
17 |
audio_path: str,
|
18 |
+
path_name: str,
|
19 |
+
difficulty: str = "intermediate",
|
20 |
+
include_resources: bool = True) -> tuple:
|
21 |
try:
|
22 |
# Transcribe audio
|
23 |
transcription = self.transcriber(audio_path)["text"]
|
|
|
35 |
max_length=300,
|
36 |
num_return_sequences=1)[0]["generated_text"]
|
37 |
|
38 |
+
if include_resources:
|
39 |
+
resources = self._generate_resources()
|
40 |
+
analysis += "\n\n" + resources
|
41 |
+
|
42 |
+
return (
|
43 |
+
gr.Textbox.update(value=transcription, visible=True),
|
44 |
+
gr.Textbox.update(value=analysis, visible=True),
|
45 |
+
gr.Markdown.update(visible=True, value="β
Learning path generated successfully!"),
|
46 |
+
gr.Button.update(interactive=True)
|
47 |
+
)
|
48 |
except Exception as e:
|
49 |
+
return (
|
50 |
+
gr.Textbox.update(value=f"Error: {str(e)}", visible=True),
|
51 |
+
gr.Textbox.update(value="Could not generate analysis.", visible=True),
|
52 |
+
gr.Markdown.update(visible=True, value="β An error occurred"),
|
53 |
+
gr.Button.update(interactive=True)
|
54 |
+
)
|
55 |
+
|
56 |
+
def _generate_resources(self) -> str:
|
57 |
+
return """
|
58 |
+
π Recommended Resources:
|
59 |
+
|
60 |
+
1. Books:
|
61 |
+
- "Essential Guide"
|
62 |
+
- "Advanced Techniques"
|
63 |
+
|
64 |
+
2. Online Courses:
|
65 |
+
- Coursera: "Topic Specialization"
|
66 |
+
- edX: "Advanced Course"
|
67 |
+
|
68 |
+
3. Practical Resources:
|
69 |
+
- Interactive tutorials
|
70 |
+
- Practice exercises
|
71 |
+
- Real-world projects
|
72 |
+
"""
|
73 |
|
74 |
def create_interface():
|
75 |
+
with gr.Blocks(theme=gr.themes.Soft(
|
76 |
+
primary_hue="blue",
|
77 |
+
secondary_hue="purple",
|
78 |
+
neutral_hue="gray"
|
79 |
+
)) as app:
|
80 |
+
gr.Markdown("""
|
81 |
+
# π Learning Path Generator
|
82 |
+
|
83 |
+
Upload an audio file describing your learning goals and receive a personalized learning path!
|
84 |
+
""")
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Column(scale=2):
|
88 |
+
# Input components
|
89 |
+
with gr.Group():
|
90 |
+
gr.Markdown("### π Input")
|
91 |
+
audio_input = gr.Audio(
|
92 |
+
type="filepath",
|
93 |
+
label="Audio Input",
|
94 |
+
description="Record or upload an audio describing your goals",
|
95 |
+
sources=["microphone", "upload"],
|
96 |
+
)
|
97 |
+
|
98 |
+
with gr.Row():
|
99 |
+
path_name = gr.Textbox(
|
100 |
+
label="Path Name",
|
101 |
+
placeholder="Give your learning path a name",
|
102 |
+
scale=2
|
103 |
+
)
|
104 |
+
difficulty = gr.Dropdown(
|
105 |
+
choices=["beginner", "intermediate", "advanced"],
|
106 |
+
value="intermediate",
|
107 |
+
label="Difficulty Level",
|
108 |
+
scale=1
|
109 |
+
)
|
110 |
+
|
111 |
+
include_resources = gr.Checkbox(
|
112 |
+
label="Include Recommended Resources",
|
113 |
+
value=True,
|
114 |
+
info="Add curated learning resources to your path"
|
115 |
+
)
|
116 |
+
|
117 |
+
process_btn = gr.Button(
|
118 |
+
"π Generate Learning Path",
|
119 |
+
variant="primary",
|
120 |
+
scale=2
|
121 |
+
)
|
122 |
+
|
123 |
+
# Output components
|
124 |
+
with gr.Column(scale=2):
|
125 |
+
with gr.Group():
|
126 |
+
gr.Markdown("### π Output")
|
127 |
+
status = gr.Markdown(visible=False)
|
128 |
+
|
129 |
+
with gr.Accordion("Audio Transcription", open=False):
|
130 |
+
transcription = gr.Textbox(
|
131 |
+
label="What we heard",
|
132 |
+
lines=4,
|
133 |
+
visible=False
|
134 |
+
)
|
135 |
+
|
136 |
+
analysis = gr.Textbox(
|
137 |
+
label="Your Learning Path",
|
138 |
+
lines=10,
|
139 |
+
visible=False
|
140 |
+
)
|
141 |
+
|
142 |
+
# Event handlers
|
143 |
+
process_btn.click(
|
144 |
+
fn=LearningPathGenerator().process_audio,
|
145 |
+
inputs=[audio_input, path_name, difficulty, include_resources],
|
146 |
+
outputs=[transcription, analysis, status, process_btn],
|
147 |
+
api_name="generate_path"
|
148 |
+
)
|
149 |
+
|
150 |
+
# Examples
|
151 |
+
gr.Examples(
|
152 |
+
examples=[
|
153 |
+
["path_audio.mp3", "Python Programming", "beginner", True],
|
154 |
+
["path_audio2.mp3", "Data Science", "intermediate", True],
|
155 |
+
],
|
156 |
+
inputs=[audio_input, path_name, difficulty, include_resources],
|
157 |
+
outputs=[transcription, analysis, status, process_btn],
|
158 |
+
cache_examples=True,
|
159 |
+
)
|
160 |
+
|
161 |
+
# Add additional info
|
162 |
+
gr.Markdown("""
|
163 |
+
### π Tips
|
164 |
+
- Speak clearly and describe your learning goals in detail
|
165 |
+
- Mention any previous experience in the subject
|
166 |
+
- Include any specific areas you want to focus on
|
167 |
+
""")
|
168 |
+
|
169 |
return app
|
170 |
|
171 |
if __name__ == "__main__":
|
172 |
app = create_interface()
|
173 |
+
app.queue()
|
174 |
app.launch()
|