hsuwill000 commited on
Commit
7b9aa9d
·
verified ·
1 Parent(s): 13a2046

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -2,13 +2,13 @@ import gradio as gr
2
  from gradio_client import Client
3
  from PIL import Image
4
  import os
5
- import time
6
  import traceback
7
  import random
8
  import time
9
 
 
10
  clients = [
11
- Client("hsuwill000/LCM_SoteMix_OpenVINO_CPU_Space_TAESD") ,
12
  Client("HelloSun/LCM_Dreamshaper_v7-int8-ov")
13
  ]
14
 
@@ -19,10 +19,8 @@ count = 0
19
  def infer_gradio(prompt: str):
20
  global count
21
  random.seed(time.time())
22
- # Create a Client instance to communicate with the Hugging Face space
23
- #client = Client(random.choice(repos))
24
- client = random.choice(clients)
25
-
26
 
27
  # Prepare the inputs for the prediction
28
  inputs = {
@@ -31,11 +29,11 @@ def infer_gradio(prompt: str):
31
  }
32
 
33
  try:
34
- # Send the request to the model and receive the image
35
  result = client.predict(inputs, api_name="/infer")
36
 
37
- # Open the resulting image
38
- image = Image.open(result)
39
 
40
  # Create a unique filename to save the image
41
  filename = f"img_{count:08d}.jpg"
@@ -62,13 +60,13 @@ with gr.Blocks() as demo:
62
  with gr.Row(): # Use a Row to place the prompt input and the button side by side
63
  prompt_input = gr.Textbox(
64
  label="Enter Your Prompt",
65
- show_label = "False",
66
  placeholder="Type your prompt for image generation here",
67
  lines=1, # Set the input to be only one line tall
68
  interactive=True # Allow user to interact with the textbox
69
  )
70
 
71
- # Change the button text to "RUN:" and align it with the prompt input
72
  run_button = gr.Button("RUN")
73
 
74
  # Output image display area
@@ -77,4 +75,4 @@ with gr.Blocks() as demo:
77
  # Connecting the button click to the image generation function
78
  run_button.click(infer_gradio, inputs=prompt_input, outputs=output_image)
79
 
80
- demo.launch()
 
2
  from gradio_client import Client
3
  from PIL import Image
4
  import os
 
5
  import traceback
6
  import random
7
  import time
8
 
9
+ # Create Client instances for the repositories
10
  clients = [
11
+ Client("hsuwill000/LCM_SoteMix_OpenVINO_CPU_Space_TAESD"),
12
  Client("HelloSun/LCM_Dreamshaper_v7-int8-ov")
13
  ]
14
 
 
19
  def infer_gradio(prompt: str):
20
  global count
21
  random.seed(time.time())
22
+ # Randomly choose a client
23
+ client = random.choice(clients)
 
 
24
 
25
  # Prepare the inputs for the prediction
26
  inputs = {
 
29
  }
30
 
31
  try:
32
+ # Send the request to the model and receive the result (image URL or file path)
33
  result = client.predict(inputs, api_name="/infer")
34
 
35
+ # Assuming the result is a URL or path, use it to open the image
36
+ image = Image.open(result) # If the result is a URL, ensure you download it first
37
 
38
  # Create a unique filename to save the image
39
  filename = f"img_{count:08d}.jpg"
 
60
  with gr.Row(): # Use a Row to place the prompt input and the button side by side
61
  prompt_input = gr.Textbox(
62
  label="Enter Your Prompt",
63
+ show_label=False,
64
  placeholder="Type your prompt for image generation here",
65
  lines=1, # Set the input to be only one line tall
66
  interactive=True # Allow user to interact with the textbox
67
  )
68
 
69
+ # Change the button text to "RUN" and align it with the prompt input
70
  run_button = gr.Button("RUN")
71
 
72
  # Output image display area
 
75
  # Connecting the button click to the image generation function
76
  run_button.click(infer_gradio, inputs=prompt_input, outputs=output_image)
77
 
78
+ demo.launch()