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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -1,33 +1,24 @@
1
  import gradio as gr
2
- from diffusers import DiffusionPipeline
3
- import torch
4
 
5
- import requests
 
6
 
7
- API_URL = "https://router.huggingface.co/hf-inference/v1"
8
- headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxx"}
9
-
10
- def query(payload):
11
- response = requests.post(API_URL, headers=headers, json=payload)
12
- return response.content
13
-
14
- # Load the FLUX.1-dev model from Hugging Face
15
- pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16)
16
- pipe = pipe.to("cuda")
17
-
18
- # Define a function to generate an image based on the prompt
19
  def generate_image(prompt: str):
20
- # Generate the image using the pipeline
21
- image = pipe(prompt).images[0]
22
  return image
23
 
24
  # Create the Gradio interface
25
- iface = gr.Interface(fn=generate_image,
26
- inputs="text",
27
- outputs="image",
28
- title="Text-to-Image with FLUX.1-dev",
29
- description="Enter a prompt to generate an image using the FLUX.1-dev model.")
 
 
 
 
30
 
31
- # Launch the app
32
- iface.launch()
33
 
 
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