RAMYASRI-39 commited on
Commit
09c04f2
·
verified ·
1 Parent(s): 03def11

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -0
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 input components
38
+ prompt_input = gr.inputs.Textbox(
39
+ lines=2,
40
+ placeholder="Enter your prompt here...",
41
+ label="Prompt"
42
+ )
43
+
44
+ height_input = gr.inputs.Slider(
45
+ minimum=256,
46
+ maximum=2048,
47
+ step=64,
48
+ default=1024,
49
+ label="Image Height"
50
+ )
51
+
52
+ width_input = gr.inputs.Slider(
53
+ minimum=256,
54
+ maximum=2048,
55
+ step=64,
56
+ default=1024,
57
+ label="Image Width"
58
+ )
59
+
60
+ steps_input = gr.inputs.Slider(
61
+ minimum=1,
62
+ maximum=50,
63
+ step=1,
64
+ default=8,
65
+ label="Inference Steps"
66
+ )
67
+
68
+ scale_input = gr.inputs.Slider(
69
+ minimum=1.0,
70
+ maximum=10.0,
71
+ step=0.1,
72
+ default=3.5,
73
+ label="Guidance Scale"
74
+ )
75
+
76
+ seed_input = gr.inputs.Number(
77
+ default=3413,
78
+ label="Seed",
79
+ precision=0
80
+ )
81
+
82
+ # Define the output component
83
+ image_output = gr.outputs.Image(label="Generated Image")
84
+
85
+ # Create the Gradio interface
86
+ iface = gr.Interface(
87
+ fn=generate_image,
88
+ inputs=[prompt_input, height_input, width_input, steps_input, scale_input, seed_input],
89
+ outputs=image_output,
90
+ title="Hyper-FLUX-8Steps-LoRA Image Generator",
91
+ description="Generate images from text prompts using the Hyper-FLUX-8Steps-LoRA model.",
92
+ examples=[
93
+ ["A serene landscape with mountains and a river", 1024, 1024, 8, 3.5, 42],
94
+ ["A futuristic city skyline at sunset", 1024, 1024, 8, 3.5, 1234],
95
+ ["An abstract painting with vibrant colors", 1024, 1024, 8, 3.5, 5678],
96
+ ],
97
+ allow_flagging="never"
98
+ )
99
+
100
+ # Launch the interface
101
+ if __name__ == "__main__":
102
+ iface.launch()