Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import generate_lesson, generate_image
|
| 3 |
|
| 4 |
-
# Lesson topics (add JS, CSS, HTML as needed)
|
| 5 |
TOPICS = [
|
| 6 |
"Recursion", "Fibonacci sequence", "Loops",
|
| 7 |
"Dictionary usage", "List comprehensions",
|
|
@@ -14,30 +13,27 @@ with gr.Blocks(
|
|
| 14 |
css="""
|
| 15 |
body { background:#111; color:#fa29bc; font-family:Consolas, monospace; }
|
| 16 |
footer { display:none; }
|
|
|
|
|
|
|
| 17 |
button { background:#fa29bc; color:white; border:none; padding:8px 12px; border-radius:6px; }
|
| 18 |
"""
|
| 19 |
) as demo:
|
| 20 |
|
| 21 |
-
gr.HTML("""
|
| 22 |
-
<head>
|
| 23 |
-
<link rel="icon" type="image/png" href="https://i.imgur.com/qF9S2GX.png">
|
| 24 |
-
<title>CodeMode</title>
|
| 25 |
-
</head>
|
| 26 |
-
""")
|
| 27 |
-
|
| 28 |
with gr.Column():
|
| 29 |
topic_dropdown = gr.Dropdown(choices=TOPICS, label="Choose Topic", value=TOPICS[0])
|
| 30 |
generate_btn = gr.Button("Generate Lesson")
|
| 31 |
|
| 32 |
-
|
| 33 |
-
lesson_image = gr.Image(
|
| 34 |
|
| 35 |
def generate(topic):
|
| 36 |
-
|
| 37 |
image_path = generate_image(topic)
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
generate_btn.click(fn=generate, inputs=topic_dropdown, outputs=[
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import generate_lesson, generate_image
|
| 3 |
|
|
|
|
| 4 |
TOPICS = [
|
| 5 |
"Recursion", "Fibonacci sequence", "Loops",
|
| 6 |
"Dictionary usage", "List comprehensions",
|
|
|
|
| 13 |
css="""
|
| 14 |
body { background:#111; color:#fa29bc; font-family:Consolas, monospace; }
|
| 15 |
footer { display:none; }
|
| 16 |
+
.card { background:#1a1a1a; padding:20px; border-radius:12px; margin-bottom:20px; }
|
| 17 |
+
.card pre { background:#222; padding:12px; border-radius:8px; overflow-x:auto; }
|
| 18 |
button { background:#fa29bc; color:white; border:none; padding:8px 12px; border-radius:6px; }
|
| 19 |
"""
|
| 20 |
) as demo:
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
with gr.Column():
|
| 23 |
topic_dropdown = gr.Dropdown(choices=TOPICS, label="Choose Topic", value=TOPICS[0])
|
| 24 |
generate_btn = gr.Button("Generate Lesson")
|
| 25 |
|
| 26 |
+
lesson_output = gr.Markdown()
|
| 27 |
+
lesson_image = gr.Image()
|
| 28 |
|
| 29 |
def generate(topic):
|
| 30 |
+
_, lesson_text = generate_lesson(topic)
|
| 31 |
image_path = generate_image(topic)
|
| 32 |
+
# Wrap lesson text in a card
|
| 33 |
+
card_text = f"### Lesson: {topic}\n<div class='card'><pre>{lesson_text}</pre></div>"
|
| 34 |
+
return card_text, image_path
|
| 35 |
|
| 36 |
+
generate_btn.click(fn=generate, inputs=topic_dropdown, outputs=[lesson_output, lesson_image])
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
demo.launch()
|