Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,23 +5,20 @@ import os
|
|
5 |
import time
|
6 |
import traceback
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
Client("HelloSun/LCM_Dreamshaper_v7-int8-ov")
|
12 |
]
|
13 |
|
14 |
# Counter for image filenames to avoid overwriting
|
15 |
count = 0
|
16 |
-
|
17 |
-
# Global counter for selecting clients in order
|
18 |
-
client_index = 0
|
19 |
|
20 |
# Gradio Interface Function to handle image generation
|
21 |
def infer_gradio(prompt: str):
|
22 |
-
global count,
|
23 |
-
#
|
24 |
-
client =
|
25 |
|
26 |
# Prepare the inputs for the prediction
|
27 |
inputs = {
|
@@ -30,7 +27,7 @@ def infer_gradio(prompt: str):
|
|
30 |
}
|
31 |
|
32 |
try:
|
33 |
-
# Send the request to the model and receive the
|
34 |
result = client.predict(inputs, api_name="/infer")
|
35 |
|
36 |
# Open the resulting image
|
@@ -46,10 +43,10 @@ def infer_gradio(prompt: str):
|
|
46 |
image.save(filename)
|
47 |
print(f"Saved image as {filename}")
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
client_index = (client_index + 1) % len(clients) # Cycle through clients
|
52 |
|
|
|
53 |
return image
|
54 |
|
55 |
except Exception as e:
|
@@ -64,13 +61,13 @@ with gr.Blocks() as demo:
|
|
64 |
with gr.Row(): # Use a Row to place the prompt input and the button side by side
|
65 |
prompt_input = gr.Textbox(
|
66 |
label="Enter Your Prompt",
|
67 |
-
show_label=False,
|
68 |
placeholder="Type your prompt for image generation here",
|
69 |
lines=1, # Set the input to be only one line tall
|
70 |
interactive=True # Allow user to interact with the textbox
|
71 |
)
|
72 |
|
73 |
-
# Change the button text to "RUN" and align it with the prompt input
|
74 |
run_button = gr.Button("RUN")
|
75 |
|
76 |
# Output image display area
|
|
|
5 |
import time
|
6 |
import traceback
|
7 |
|
8 |
+
repos = [
|
9 |
+
"hsuwill000/LCM_SoteMix_OpenVINO_CPU_Space_TAESD",
|
10 |
+
"HelloSun/LCM_Dreamshaper_v7-int8-ov"
|
|
|
11 |
]
|
12 |
|
13 |
# Counter for image filenames to avoid overwriting
|
14 |
count = 0
|
15 |
+
repo_index = 0 # This will keep track of the current repository
|
|
|
|
|
16 |
|
17 |
# Gradio Interface Function to handle image generation
|
18 |
def infer_gradio(prompt: str):
|
19 |
+
global count, repo_index
|
20 |
+
# Create a Client instance to communicate with the Hugging Face space
|
21 |
+
client = Client(repos[repo_index])
|
22 |
|
23 |
# Prepare the inputs for the prediction
|
24 |
inputs = {
|
|
|
27 |
}
|
28 |
|
29 |
try:
|
30 |
+
# Send the request to the model and receive the image
|
31 |
result = client.predict(inputs, api_name="/infer")
|
32 |
|
33 |
# Open the resulting image
|
|
|
43 |
image.save(filename)
|
44 |
print(f"Saved image as {filename}")
|
45 |
|
46 |
+
# Increment the repo_index to choose the next repository in the list
|
47 |
+
repo_index = (repo_index + 1) % len(repos) # Cycle through repos list
|
|
|
48 |
|
49 |
+
# Return the image to be displayed in Gradio
|
50 |
return image
|
51 |
|
52 |
except Exception as e:
|
|
|
61 |
with gr.Row(): # Use a Row to place the prompt input and the button side by side
|
62 |
prompt_input = gr.Textbox(
|
63 |
label="Enter Your Prompt",
|
64 |
+
show_label = "False",
|
65 |
placeholder="Type your prompt for image generation here",
|
66 |
lines=1, # Set the input to be only one line tall
|
67 |
interactive=True # Allow user to interact with the textbox
|
68 |
)
|
69 |
|
70 |
+
# Change the button text to "RUN:" and align it with the prompt input
|
71 |
run_button = gr.Button("RUN")
|
72 |
|
73 |
# Output image display area
|