mrbeliever commited on
Commit
cbaea01
·
verified ·
1 Parent(s): 9546b81

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Load multiple models
4
+ model1 = gr.load("models/Lykon/dreamshaper-xl-turbo")
5
+ model2 = gr.load("models/hakurei/waifu-diffusion")
6
+ model3 = gr.load("models/runwayml/stable-diffusion-v1-5")
7
+ model4 = gr.load("models/stablediffusionapi/juggernaut-xl-v5")
8
+ model5 = gr.load("models/stabilityai/stable-diffusion-xl-base-1.0")
9
+
10
+ # Function to switch between models
11
+ def generate_image(model, text_input):
12
+ return model(text_input)
13
+
14
+ # Define the models and their names
15
+ models = {
16
+ "Model 1": model1,
17
+ "Model 2": model2,
18
+ "Model 3": model3,
19
+ "Model 4": model4,
20
+ "Model 5": model5
21
+ }
22
+
23
+ # Create a dropdown to select the model
24
+ model_dropdown = gr.DropDown(choices=list(models.keys()), label="Select Model")
25
+
26
+ # Create the input text box
27
+ input_text = gr.Textbox(default="Enter text here", label="Input Text")
28
+
29
+ # Create the output image
30
+ output_image = gr.Image()
31
+
32
+ # Create a function that will be called when the "Generate" button is clicked
33
+ def generate_button_click():
34
+ selected_model_name = model_dropdown.value
35
+ selected_model = models[selected_model_name]
36
+ result_image = generate_image(selected_model, input_text.value)
37
+ output_image.image(result_image)
38
+
39
+ # Create the interface
40
+ iface = gr.Interface(
41
+ fn=generate_button_click,
42
+ inputs=[model_dropdown, input_text],
43
+ outputs=output_image,
44
+ )
45
+
46
+ # Launch the interface
47
+ iface.launch()