hanjiaming.0208 commited on
Commit
134a323
Β·
1 Parent(s): a2552b3
Files changed (1) hide show
  1. app.py +52 -42
app.py CHANGED
@@ -65,52 +65,62 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
65
  elem_id="title",
66
  )
67
  with gr.Tab("Image Generation"):
68
- with gr.Row():
69
- with gr.Column(scale=1):
70
- prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt")
71
- with gr.Accordion("Advanced Settings", open=False):
72
- resolution = gr.Radio(
73
- ["512px", "1024px"], value="1024px", label="Resolution"
74
- )
75
- top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
76
- top_k = gr.Slider(1, 2000, value=1200, step=10, label="Top-k")
77
- cfg_scale = gr.Slider(1.0, 20.0, value=4.0, step=0.5, label="CFG Scale")
78
- with gr.Row():
79
- generate_btn = gr.Button("Generate")
80
- clear_btn = gr.Button("Clear")
81
- with gr.Column(scale=2):
82
- output_image = gr.Image(label="Generated Image")
83
-
84
- generate_btn.click(
85
- generate_image,
86
- inputs=[prompt, resolution, top_p, top_k, cfg_scale],
87
- outputs=output_image
88
- )
89
- clear_btn.click(
90
- clear_inputs_t2i,
91
- outputs=[prompt, output_image]
92
- )
93
-
94
- with gr.Tab("Image Understanding"):
95
  with gr.Row():
96
  with gr.Column(scale=1):
97
- image_input = gr.Image(label="Upload Image", type="pil")
98
- question_input = gr.Textbox(label="Instruction", value="Describe the image shortly.")
 
 
 
 
 
 
99
  with gr.Row():
100
- qa_btn = gr.Button("Generate")
101
- clear_btn_i2t = gr.Button("Clear")
102
- with gr.Column(scale=1):
103
- answer_output = gr.Textbox(label="Response", lines=4)
104
-
105
- qa_btn.click(
106
- understand_image,
107
- inputs=[image_input, question_input],
108
- outputs=answer_output
 
 
 
 
 
 
 
 
 
 
109
  )
110
-
111
- clear_btn_i2t.click(
112
- clear_inputs_i2t,
113
- outputs=[image_input, question_input, answer_output]
114
  )
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  demo.launch(share=True)
 
65
  elem_id="title",
66
  )
67
  with gr.Tab("Image Generation"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  with gr.Row():
69
  with gr.Column(scale=1):
70
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt")
71
+ with gr.Accordion("Advanced Settings", open=False):
72
+ resolution = gr.Radio(
73
+ ["512px", "1024px"], value="1024px", label="Resolution"
74
+ )
75
+ top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
76
+ top_k = gr.Slider(1, 2000, value=1200, step=10, label="Top-k")
77
+ cfg_scale = gr.Slider(1.0, 20.0, value=4.0, step=0.5, label="CFG Scale")
78
  with gr.Row():
79
+ generate_btn = gr.Button("Generate")
80
+ clear_btn = gr.Button("Clear")
81
+ with gr.Column(scale=2):
82
+ output_image = gr.Image(label="Generated Image")
83
+ with gr.Row():
84
+ gr.Examples(
85
+ examples=[
86
+ ["a vibrant arrangement of blue and yellow flowers, with delicate petals and lush green stems, placed in a clear glass vase. The vase is situated on a polished wooden table, which reflects the soft light illuminating the room. Around the vase, there are a few scattered leaves, adding a touch of natural charm to the setting.", "1024px", 0.95, 1200, 4.0],
87
+ ["a cat", "512px", 0.95, 1200, 4.0],
88
+ ],
89
+ inputs=[prompt, resolution, top_p, top_k, cfg_scale],
90
+ label="Example"
91
+ )
92
+
93
+
94
+ generate_btn.click(
95
+ generate_image,
96
+ inputs=[prompt, resolution, top_p, top_k, cfg_scale],
97
+ outputs=output_image
98
  )
99
+ clear_btn.click(
100
+ clear_inputs_t2i,
101
+ outputs=[prompt, output_image]
 
102
  )
103
 
104
+ with gr.Tab("Image Understanding"):
105
+ with gr.Row():
106
+ with gr.Column(scale=1):
107
+ image_input = gr.Image(label="Upload Image", type="pil")
108
+ question_input = gr.Textbox(label="Instruction", value="Describe the image shortly.")
109
+ with gr.Row():
110
+ qa_btn = gr.Button("Generate")
111
+ clear_btn_i2t = gr.Button("Clear")
112
+ with gr.Column(scale=1):
113
+ answer_output = gr.Textbox(label="Response", lines=4)
114
+
115
+ qa_btn.click(
116
+ understand_image,
117
+ inputs=[image_input, question_input],
118
+ outputs=answer_output
119
+ )
120
+
121
+ clear_btn_i2t.click(
122
+ clear_inputs_i2t,
123
+ outputs=[image_input, question_input, answer_output]
124
+ )
125
+
126
  demo.launch(share=True)