RandomOnHuggingFace commited on
Commit
919541f
verified
1 Parent(s): fcbf8c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -10,21 +10,21 @@ stable_diffusion = InferenceClient("stabilityai/stable-diffusion-3.5-large-turbo
10
  dalle_3 = InferenceClient("ehristoforu/dalle-3-xl-v2")
11
  flux = InferenceClient("black-forest-labs/FLUX.1-dev")
12
 
13
- def generate_image(model_choice, prompt, num_images=1):
14
  """Function to generate images based on the chosen model."""
15
  if model_choice == "Stable Diffusion 3.5 Large Turbo":
16
- response = stable_diffusion.text_to_image(prompt, num_images=num_images)
17
  elif model_choice == "DALL路E 3 XL":
18
- response = dalle_3.text_to_image(prompt, num_images=num_images)
19
  elif model_choice == "FLUX.1-dev":
20
- response = flux.text_to_image(prompt, num_images=num_images)
21
 
22
  # Return the generated images (assuming each model returns a URL or image object)
23
  return response[0]["image"] # Adjust as needed based on actual response format
24
 
25
  # Create a function to handle user input
26
- def generate_image_response(prompt, model_choice):
27
- image = generate_image(model_choice, prompt)
28
  return image
29
 
30
  # Define Gradio Interface
@@ -32,23 +32,14 @@ demo = gr.Interface(
32
  fn=generate_image_response,
33
  inputs=[
34
  gr.Textbox(label="Enter your prompt here"),
35
- gr.Dropdown(choices=["Stable Diffusion 3.5 Large Turbo", "DALL路E 3 XL", "FLUX.1-dev"], label="Choose Model", value="Stable Diffusion 3.5 Large Turbo")
 
 
 
36
  ],
37
  outputs="image",
38
  title="DreamXL Image",
39
- description="Welcome to DreamXL Image! Choose a model and input your prompt to generate stunning visuals.",
40
- additional_inputs=[
41
- gr.Textbox(value="You are a helpful image generation assistant.", label="System message"),
42
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
43
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
44
- gr.Slider(
45
- minimum=0.1,
46
- maximum=1.0,
47
- value=0.95,
48
- step=0.05,
49
- label="Top-p (nucleus sampling)",
50
- ),
51
- ],
52
  )
53
 
54
  if __name__ == "__main__":
 
10
  dalle_3 = InferenceClient("ehristoforu/dalle-3-xl-v2")
11
  flux = InferenceClient("black-forest-labs/FLUX.1-dev")
12
 
13
+ def generate_image(model_choice, prompt, negative_prompt, image_size, num_images=1):
14
  """Function to generate images based on the chosen model."""
15
  if model_choice == "Stable Diffusion 3.5 Large Turbo":
16
+ response = stable_diffusion.text_to_image(prompt, negative_prompt=negative_prompt, num_images=num_images, size=image_size)
17
  elif model_choice == "DALL路E 3 XL":
18
+ response = dalle_3.text_to_image(prompt, negative_prompt=negative_prompt, num_images=num_images, size=image_size)
19
  elif model_choice == "FLUX.1-dev":
20
+ response = flux.text_to_image(prompt, negative_prompt=negative_prompt, num_images=num_images, size=image_size)
21
 
22
  # Return the generated images (assuming each model returns a URL or image object)
23
  return response[0]["image"] # Adjust as needed based on actual response format
24
 
25
  # Create a function to handle user input
26
+ def generate_image_response(prompt, model_choice, negative_prompt, image_size, num_images):
27
+ image = generate_image(model_choice, prompt, negative_prompt, image_size, num_images)
28
  return image
29
 
30
  # Define Gradio Interface
 
32
  fn=generate_image_response,
33
  inputs=[
34
  gr.Textbox(label="Enter your prompt here"),
35
+ gr.Dropdown(choices=["Stable Diffusion 3.5 Large Turbo", "DALL路E 3 XL", "FLUX.1-dev"], label="Choose Model", value="Stable Diffusion 3.5 Large Turbo"),
36
+ gr.Textbox(value="", label="Negative prompt (what you don't want in the image)"),
37
+ gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of images to generate"),
38
+ gr.Slider(minimum=256, maximum=1024, value=512, step=64, label="Image size (width & height)"),
39
  ],
40
  outputs="image",
41
  title="DreamXL Image",
42
+ description="Welcome to DreamXL Image! Choose a model, input your prompt, negative prompt, and set image parameters to generate stunning visuals.",
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
 
45
  if __name__ == "__main__":