RAMYASRI-39 commited on
Commit
d748563
·
verified ·
1 Parent(s): 3f9b814

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -55
app.py CHANGED
@@ -1,99 +1,100 @@
1
  import gradio as gr
2
  from gradio_client import Client
 
3
 
4
- # Initialize the Hugging Face client with the specific model
5
  client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")
6
 
7
- def generate_image(prompt, height, width, steps, scale, seed):
8
  """
9
- Function to generate an image based on the provided prompt and parameters.
10
-
11
- Args:
12
- prompt (str): The text prompt to generate the image.
13
- height (int): The height of the generated image.
14
- width (int): The width of the generated image.
15
- steps (int): Number of inference steps.
16
- scale (float): Guidance scale for the image generation.
17
- seed (int): Seed for random number generator to ensure reproducibility.
18
-
19
  Returns:
20
- Image: Generated image based on the prompt and parameters.
21
  """
 
 
 
 
22
  try:
23
- # Call the predict method of the client with provided parameters
24
  result = client.predict(
25
- height=height,
26
- width=width,
27
- steps=steps,
28
- scales=scale,
29
  prompt=prompt,
30
- seed=seed,
31
  api_name="/process_image"
32
  )
33
  return result
34
  except Exception as e:
35
  return f"An error occurred: {e}"
36
 
37
- # Define the Gradio interface using the updated API
38
  with gr.Blocks() as demo:
39
  gr.Markdown("# Hyper-FLUX-8Steps-LoRA Image Generator")
40
- gr.Markdown(
41
- """
42
- Enter a text prompt and adjust the parameters to generate an image using the Hyper-FLUX-8Steps-LoRA model.
43
- """
44
- )
45
-
46
  with gr.Row():
47
  with gr.Column():
48
  prompt = gr.Textbox(
49
  label="Prompt",
50
- placeholder="Enter your image description here...",
51
  lines=2
52
  )
53
- height = gr.Slider(
54
  label="Height",
55
- minimum=256,
56
- maximum=2048,
57
- step=64,
58
- value=1024
59
  )
60
- width = gr.Slider(
61
  label="Width",
62
- minimum=256,
63
- maximum=2048,
64
- step=64,
65
- value=1024
66
  )
67
- steps = gr.Slider(
68
  label="Steps",
69
- minimum=1,
70
- maximum=50,
71
- step=1,
72
- value=8
73
  )
74
- scale = gr.Slider(
75
  label="Scale",
76
- minimum=1.0,
77
- maximum=10.0,
78
- step=0.1,
79
- value=3.5
80
  )
81
  seed = gr.Number(
82
  label="Seed",
83
  value=3413,
84
- precision=0
 
85
  )
86
- generate_btn = gr.Button("Generate Image")
87
-
88
  with gr.Column():
89
- output = gr.Image(label="Generated Image")
90
-
91
- generate_btn.click(
 
92
  fn=generate_image,
93
- inputs=[prompt, height, width, steps, scale, seed],
94
- outputs=output
95
  )
96
 
 
 
 
97
  # Launch the Gradio app
98
  if __name__ == "__main__":
99
  demo.launch()
 
1
  import gradio as gr
2
  from gradio_client import Client
3
+ import random
4
 
5
+ # Initialize the client for the Hugging Face Space
6
  client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")
7
 
8
+ def generate_image(prompt, height, width, steps, scales, seed):
9
  """
10
+ Generates an image based on the provided parameters by calling the Hugging Face Space API.
11
+
12
+ Parameters:
13
+ - prompt (str): The text prompt for image generation.
14
+ - height (int): The height of the generated image.
15
+ - width (int): The width of the generated image.
16
+ - steps (int): The number of steps for the image generation process.
17
+ - scales (float): The scaling factor.
18
+ - seed (int): The seed for random number generation to ensure reproducibility.
19
+
20
  Returns:
21
+ - result (str or Image): The generated image or a link to it.
22
  """
23
+ # Generate a random seed if not provided
24
+ if not seed:
25
+ seed = random.randint(0, 100000)
26
+
27
  try:
 
28
  result = client.predict(
29
+ height=int(height),
30
+ width=int(width),
31
+ steps=int(steps),
32
+ scales=float(scales),
33
  prompt=prompt,
34
+ seed=int(seed),
35
  api_name="/process_image"
36
  )
37
  return result
38
  except Exception as e:
39
  return f"An error occurred: {e}"
40
 
41
+ # Define the Gradio interface
42
  with gr.Blocks() as demo:
43
  gr.Markdown("# Hyper-FLUX-8Steps-LoRA Image Generator")
44
+ gr.Markdown("Generate images based on your text prompts using the Hyper-FLUX-8Steps-LoRA model.")
45
+
 
 
 
 
46
  with gr.Row():
47
  with gr.Column():
48
  prompt = gr.Textbox(
49
  label="Prompt",
50
+ placeholder="Enter your descriptive text here...",
51
  lines=2
52
  )
53
+ height = gr.Number(
54
  label="Height",
55
+ value=1024,
56
+ precision=0,
57
+ interactive=True
 
58
  )
59
+ width = gr.Number(
60
  label="Width",
61
+ value=1024,
62
+ precision=0,
63
+ interactive=True
 
64
  )
65
+ steps = gr.Number(
66
  label="Steps",
67
+ value=8,
68
+ precision=0,
69
+ interactive=True
 
70
  )
71
+ scales = gr.Number(
72
  label="Scale",
73
+ value=3.5,
74
+ precision=1,
75
+ interactive=True
 
76
  )
77
  seed = gr.Number(
78
  label="Seed",
79
  value=3413,
80
+ precision=0,
81
+ interactive=True
82
  )
83
+ generate_button = gr.Button("Generate Image")
84
+
85
  with gr.Column():
86
+ output_image = gr.Image(label="Generated Image", interactive=False)
87
+
88
+ # Define the button click action
89
+ generate_button.click(
90
  fn=generate_image,
91
+ inputs=[prompt, height, width, steps, scales, seed],
92
+ outputs=output_image
93
  )
94
 
95
+ # Optional: Add a footer or additional information
96
+ gr.Markdown("© 2024 Your Name. All rights reserved.")
97
+
98
  # Launch the Gradio app
99
  if __name__ == "__main__":
100
  demo.launch()