Spaces:
Sleeping
Sleeping
美化UI界面:添加新布局和样式
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import numpy as np
|
|
6 |
from fastapi import FastAPI, File, UploadFile
|
7 |
from PIL import Image
|
8 |
import io
|
|
|
9 |
|
10 |
# 初始化 FastAPI
|
11 |
app = FastAPI()
|
@@ -117,15 +118,25 @@ with gr.Blocks(theme=theme) as demo:
|
|
117 |
outputs=[input_image, output_image, result_text],
|
118 |
)
|
119 |
|
120 |
-
#
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
# API端点
|
131 |
@app.post("/detect/")
|
|
|
6 |
from fastapi import FastAPI, File, UploadFile
|
7 |
from PIL import Image
|
8 |
import io
|
9 |
+
import os
|
10 |
|
11 |
# 初始化 FastAPI
|
12 |
app = FastAPI()
|
|
|
118 |
outputs=[input_image, output_image, result_text],
|
119 |
)
|
120 |
|
121 |
+
# 修改示例部分的代码
|
122 |
+
# 使用try-except来处理示例图片
|
123 |
+
try:
|
124 |
+
examples = []
|
125 |
+
if os.path.exists("example1.jpg"):
|
126 |
+
examples.append("example1.jpg")
|
127 |
+
if os.path.exists("example2.jpg"):
|
128 |
+
examples.append("example2.jpg")
|
129 |
+
|
130 |
+
if examples: # 只有在有示例图片时才添加Examples组件
|
131 |
+
gr.Examples(
|
132 |
+
examples=examples,
|
133 |
+
inputs=input_image,
|
134 |
+
outputs=[output_image, result_text],
|
135 |
+
fn=detect_objects,
|
136 |
+
cache_examples=True,
|
137 |
+
)
|
138 |
+
except Exception as e:
|
139 |
+
print(f"Warning: Could not load example images: {e}")
|
140 |
|
141 |
# API端点
|
142 |
@app.post("/detect/")
|