tejas1243 commited on
Commit
55de385
·
verified ·
1 Parent(s): 66bccde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -1,23 +1,28 @@
1
  import gradio as gr
2
  from diffusers import StableDiffusionPipeline
3
  import torch
 
4
 
5
- # Load the model (Stable Diffusion XL)
6
  pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
7
- pipe.to("cpu") # CPU mode (free tier compatible)
8
 
9
- # Function to generate an image
10
- def generate_image(prompt):
 
 
 
11
  image = pipe(prompt).images[0]
12
- return image
 
13
 
14
- # Gradio interface
15
  demo = gr.Interface(
16
- fn=generate_image,
17
- inputs=gr.Textbox(label="Enter your image prompt"),
18
- outputs="image",
19
- title="Stable Diffusion XL (Free CPU Version)",
20
- description="Generate images for free using CPU mode on Hugging Face"
21
  )
22
 
23
  demo.launch()
 
1
  import gradio as gr
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
+ from transformers import pipeline
5
 
6
+ # 🎨 Load Stable Diffusion model
7
  pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
8
+ pipe.to("cpu")
9
 
10
+ # 🗣️ Load Text-to-Speech model
11
+ tts = pipeline("text-to-speech", model="nineninesix/kani-tts-370m")
12
+
13
+ # Image generation function
14
+ def generate_media(prompt):
15
  image = pipe(prompt).images[0]
16
+ audio = tts(prompt)
17
+ return image, (audio["audio"],)
18
 
19
+ # Gradio UI
20
  demo = gr.Interface(
21
+ fn=generate_media,
22
+ inputs=gr.Textbox(label="Enter your prompt"),
23
+ outputs=[gr.Image(label="Generated Image"), gr.Audio(label="AI Voice")],
24
+ title="AI Image + Voice Generator",
25
+ description="Generates an image with a matching AI voiceover using Stable Diffusion XL and KaniTTS"
26
  )
27
 
28
  demo.launch()