Naveenlara commited on
Commit
ea9b46a
·
verified ·
1 Parent(s): 42eee25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -28
app.py CHANGED
@@ -1,35 +1,44 @@
1
  import gradio as gr
2
- from diffusers import StableDiffusionPipeline
3
- import torch
4
 
5
- # Load the stable diffusion model
6
- pipe = StableDiffusionPipeline.from_pretrained(
7
- "CompVis/stable-diffusion-v1-4",
8
- revision="fp16",
9
- torch_dtype=torch.float16
10
- )
11
- pipe.to("cuda" if torch.cuda.is_available() else "cpu")
 
12
 
13
- def generate_image(prompt):
14
- image = pipe(prompt).images[0]
15
- image.save("generated_exercise.png") # Save image locally to return a downloadable version
16
- return image, "generated_exercise.png"
 
 
 
 
17
 
18
- # Example prompts
19
- examples = [
20
- ["Child to cobra pose yoga stretch"],
21
- ["Cat to cow mobility exercise"],
22
- ["Front scorpion leg raises"],
23
- ["Wall-assisted hamstring stretch"]
24
- ]
25
 
26
- # Create a Gradio interface
27
  gr.Interface(
28
- fn=generate_image,
29
- inputs=gr.Textbox(lines=2, placeholder="Enter an exercise like 'child to cobra pose'"),
30
- outputs=["image", gr.File(label="Download Image")],
31
- title="AI Exercise Visual Generator",
32
- description="Enter an exercise name. This tool will generate a visual representation using AI.",
33
- examples=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()