Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
#
|
| 27 |
gr.Interface(
|
| 28 |
-
fn=
|
| 29 |
-
inputs=gr.Textbox(
|
| 30 |
-
outputs=["
|
| 31 |
-
title="AI Exercise
|
| 32 |
-
description="
|
| 33 |
-
examples=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
).launch()
|
| 35 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import difflib
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# A simple mapping of prompt keywords to image file names
|
| 6 |
+
exercise_sets = {
|
| 7 |
+
"shoulder": "shoulder_mobility.png",
|
| 8 |
+
"neck": "neck_stretches.png",
|
| 9 |
+
"back": "back_mobility.png",
|
| 10 |
+
"full body": "full_body_mobility.png",
|
| 11 |
+
"warm up": "warmup_routine.png"
|
| 12 |
+
}
|
| 13 |
|
| 14 |
+
# Fuzzy matching prompt to known categories
|
| 15 |
+
def match_prompt_to_exercise(prompt):
|
| 16 |
+
keywords = list(exercise_sets.keys())
|
| 17 |
+
closest = difflib.get_close_matches(prompt.lower(), keywords, n=1, cutoff=0.3)
|
| 18 |
+
if closest:
|
| 19 |
+
return exercise_sets[closest[0]]
|
| 20 |
+
else:
|
| 21 |
+
return None
|
| 22 |
|
| 23 |
+
# Main function
|
| 24 |
+
def get_exercise_set(prompt):
|
| 25 |
+
matched_file = match_prompt_to_exercise(prompt)
|
| 26 |
+
if matched_file and os.path.exists(f"exercise_sets/{matched_file}"):
|
| 27 |
+
return f"exercise_sets/{matched_file}", f"exercise_sets/{matched_file}"
|
| 28 |
+
else:
|
| 29 |
+
return None, "Sorry, no matching set found. Try: 'shoulder', 'neck', 'warm up'"
|
| 30 |
|
| 31 |
+
# Interface
|
| 32 |
gr.Interface(
|
| 33 |
+
fn=get_exercise_set,
|
| 34 |
+
inputs=gr.Textbox(label="Enter your goal (e.g., 'Shoulder mobility exercises')"),
|
| 35 |
+
outputs=[gr.Image(label="Generated Exercise Sheet"), gr.File(label="Download Image")],
|
| 36 |
+
title="🧘 AI Exercise Sheet Generator",
|
| 37 |
+
description="Type a goal like 'Neck stretches' or 'Warm-up routine' to get an illustrated exercise set.",
|
| 38 |
+
examples=[
|
| 39 |
+
["Shoulder mobility exercises"],
|
| 40 |
+
["Neck stretches"],
|
| 41 |
+
["Warm-up before boxing"],
|
| 42 |
+
["Full body mobility"]
|
| 43 |
+
]
|
| 44 |
).launch()
|
|
|