broadfield-dev commited on
Commit
62d9bf1
·
verified ·
1 Parent(s): f7235bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -1,24 +1,33 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
 
3
 
4
- # List of models and their corresponding names
5
  models = [
6
  "CompVis/stable-diffusion-v1-4",
7
  "runwayml/stable-diffusion-v1-5",
8
- "hakurei/waifu-diffusion",
9
- "prompthero/openjourney",
10
- "jacek-huszar/$(IMG2TEXT_MODEL_NAME)",
11
- "cjwbw/canvae-text-to-image",
12
- "tdbooth/hollow-kingdom-ddim",
13
- "kuprel/min-dalle",
14
- "osanseviero/stable-diffusion-webui",
15
- "lambdal/text-to-image"
16
  ]
17
 
18
  def generate_image(prompt, model_name):
19
  client = InferenceClient(model_name)
20
  response = client.text_to_image(prompt)
21
- return response.image
 
 
 
 
 
 
22
 
23
  # Create Gradio Interface
24
  with gr.Blocks() as demo:
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import base64
4
+ from io import BytesIO
5
+ from PIL import Image
6
 
7
+ # Define the list of models
8
  models = [
9
  "CompVis/stable-diffusion-v1-4",
10
  "runwayml/stable-diffusion-v1-5",
11
+ "stabilityai/stable-diffusion-2-1-base",
12
+ "stabilityai/stable-diffusion-2-1",
13
+ "CompVis/ldm-text2im-large-256",
14
+ "lambdalabs/sd-text2img-base-2-0",
15
+ "ZB-Tech/Text-to-Image",
16
+ "cloudqi/cqi_text_to_image_pt_v0",
17
+ "kothariyashhh/GenAi-Texttoimage",
18
+ "sairajg/Text_To_Image"
19
  ]
20
 
21
  def generate_image(prompt, model_name):
22
  client = InferenceClient(model_name)
23
  response = client.text_to_image(prompt)
24
+
25
+ if isinstance(response, list):
26
+ image_data = response[0]['image']
27
+ image = Image.open(BytesIO(base64.b64decode(image_data)))
28
+ return image
29
+ else:
30
+ return "Failed to generate image."
31
 
32
  # Create Gradio Interface
33
  with gr.Blocks() as demo: