akhaliq HF staff ysharma HF staff commited on
Commit
804827c
1 Parent(s): ac9a931

adding the gradio-template style UI (#1)

Browse files

- adding the gradio-template style UI (ebf269942a8b2ad46493646865aeeb2510871aeb)


Co-authored-by: yuvraj sharma <ysharma@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +54 -21
app.py CHANGED
@@ -5,6 +5,19 @@ import requests
5
  from PIL import Image
6
  from io import BytesIO
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_image(prompt, api_key):
9
  # Set the API key for the current session
10
  os.environ["REPLICATE_API_TOKEN"] = api_key
@@ -28,26 +41,46 @@ def generate_image(prompt, api_key):
28
  # Return the image
29
  return image
30
 
31
- # Create the Gradio interface
32
- iface = gr.Interface(
33
- fn=generate_image,
34
- inputs=[
35
- gr.Textbox(
36
- lines=2,
37
- placeholder="Enter your prompt here...",
38
- label="Prompt"
39
- ),
40
- gr.Textbox(
41
- lines=1,
42
- placeholder="Enter your Replicate API key...",
43
- type="password",
44
- label="Replicate API Key"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  )
46
- ],
47
- outputs=gr.Image(type="pil"),
48
- title="FLUX 1.1 Pro Text-to-Image Generator",
49
- description="Generate images from text prompts using the FLUX 1.1 Pro model."
50
- )
 
51
 
52
- # Launch the Gradio app
53
- iface.launch()
 
5
  from PIL import Image
6
  from io import BytesIO
7
 
8
+ examples = [
9
+ "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
10
+ "An astronaut riding a green horse",
11
+ "A delicious ceviche cheesecake slice",
12
+ ]
13
+
14
+ css="""
15
+ #col-container {
16
+ margin: 0 auto;
17
+ max-width: 640px;
18
+ }
19
+ """
20
+
21
  def generate_image(prompt, api_key):
22
  # Set the API key for the current session
23
  os.environ["REPLICATE_API_TOKEN"] = api_key
 
41
  # Return the image
42
  return image
43
 
44
+
45
+ with gr.Blocks(css=css) as demo:
46
+
47
+ with gr.Column(elem_id="col-container"):
48
+ gr.Markdown(f"""
49
+ # FLUX 1.1 Pro Text-to-Image Generator
50
+ """)
51
+
52
+ with gr.Row():
53
+ with gr.Column():
54
+ api_key = gr.Text(
55
+ label="Replicate API Key",
56
+ show_label=False,
57
+ max_lines=1,
58
+ placeholder="Enter your Replicate API key...",
59
+ container=False,
60
+ type="password",
61
+ )
62
+ prompt = gr.Text(
63
+ label="Prompt",
64
+ show_label=False,
65
+ max_lines=1,
66
+ placeholder="Enter your prompt",
67
+ container=False,
68
+ )
69
+
70
+ run_button = gr.Button("Run", scale=0)
71
+
72
+ result = gr.Image(label="Result", show_label=False)
73
+
74
+
75
+ gr.Examples(
76
+ examples = examples,
77
+ inputs = [prompt]
78
  )
79
+ gr.on(
80
+ triggers=[run_button.click, prompt.submit],
81
+ fn = generate_image,
82
+ inputs = [prompt, api_key],
83
+ outputs = [result,]
84
+ )
85
 
86
+ demo.queue().launch()