Dannyar608 commited on
Commit
c01fe81
·
verified ·
1 Parent(s): 70eb5ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -1,24 +1,29 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Load Stable Diffusion model from Hugging Face
5
- generator = pipeline("text-to-image", model="stabilityai/stable-diffusion-3-medium-diffusers")
 
6
 
7
- # Define the chatbot function
8
- def generate_image(prompt: str):
9
- # Generate the image from the prompt
10
- image = generator(prompt)[0]["image"]
11
  return image
12
 
13
- # Create the Gradio interface
14
- iface = gr.Interface(
15
- fn=generate_image,
16
- inputs=gr.Textbox(label="Enter a description of the image"),
17
- outputs=gr.Image(label="Generated Image"),
18
- live=True
 
 
19
  )
20
 
21
- # Launch the Gradio interface
22
- iface.launch(share=True)
 
23
 
24
 
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
 
5
+ # Load the model (you can replace this with the specific Kwai-Kolors/Kolors model if available)
6
+ pipe = StableDiffusionPipeline.from_pretrained("Kwai-Kolors/Kolors")
7
+ pipe.to("cuda" if torch.cuda.is_available() else "cpu")
8
 
9
+ # Define function to generate image from text
10
+ def generate_image(prompt):
11
+ # Generate an image based on the provided text prompt
12
+ image = pipe(prompt).images[0]
13
  return image
14
 
15
+ # Create Gradio interface for chatbot
16
+ interface = gr.Interface(
17
+ fn=generate_image,
18
+ inputs=gr.Textbox(label="Enter your prompt:"),
19
+ outputs=gr.Image(type="pil"),
20
+ live=True,
21
+ title="Text-to-Image Generation",
22
+ description="Enter a text prompt to generate a photorealistic image."
23
  )
24
 
25
+ # Launch the interface
26
+ interface.launch()
27
+
28
 
29