aifeifei798 commited on
Commit
902ec6b
1 Parent(s): fe129cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -76,22 +76,34 @@ def run_example(image):
76
 
77
 
78
  css = """
79
- #output {
80
  height: 500px;
81
  overflow: auto;
82
  border: 1px solid #ccc;
83
- }
84
- #col-container {
 
85
  margin: 0 auto;
86
- max-width: auto;
87
  max-height: 360px;
88
- object-fit: contain;
 
 
 
 
 
 
 
 
 
 
89
  """
90
 
91
  with gr.Blocks(css=css) as demo:
92
  gr.Markdown(TITLE)
93
- input_img = gr.Image(elem_id="col-container",container=True,height="360",label="Input Picture")
94
  submit_btn = gr.Button(value="Submit")
95
  output_text = gr.Textbox(label="Output Text")
96
  submit_btn.click(run_example, [input_img], [output_text])
97
- demo.launch(debug=True)
 
 
76
 
77
 
78
  css = """
79
+ #output {
80
  height: 500px;
81
  overflow: auto;
82
  border: 1px solid #ccc;
83
+ }
84
+
85
+ #col-container {
86
  margin: 0 auto;
87
+ max-width: 100%; /* 确保容器宽度不超过父元素 */
88
  max-height: 360px;
89
+ display: flex; /* 使用 flexbox 布局 */
90
+ justify-content: center; /* 水平居中 */
91
+ align-items: center; /* 垂直居中 */
92
+ overflow: hidden; /* 隐藏超出容器的内容 */
93
+ }
94
+
95
+ #col-container img {
96
+ max-width: 100%; /* 图像宽度不超过容器 */
97
+ max-height: 100%; /* 图像高度不超过容器 */
98
+ object-fit: contain; /* 保持图像比例,完全显示图像 */
99
+ }
100
  """
101
 
102
  with gr.Blocks(css=css) as demo:
103
  gr.Markdown(TITLE)
104
+ input_img = gr.Image(elem_id="col-container", height="auto", label="Input Picture")
105
  submit_btn = gr.Button(value="Submit")
106
  output_text = gr.Textbox(label="Output Text")
107
  submit_btn.click(run_example, [input_img], [output_text])
108
+
109
+ demo.launch(debug=True)