Spaces:
Sleeping
Sleeping
Commit
·
10428c0
1
Parent(s):
7d0da85
Fix dependency conflicts and update UI for compatibility with Gradio 3.19.1
Browse files- app.py +21 -45
- requirements.txt +2 -2
app.py
CHANGED
|
@@ -111,7 +111,6 @@ def generate_ai_image(prompt, seed=None):
|
|
| 111 |
model_id,
|
| 112 |
torch_dtype=torch_dtype,
|
| 113 |
use_auth_token=False, # 明确不使用认证
|
| 114 |
-
revision="main", # 使用主分支
|
| 115 |
safety_checker=None, # 禁用安全检查器
|
| 116 |
)
|
| 117 |
pipe = pipe.to(device)
|
|
@@ -249,50 +248,28 @@ def generate_image(prompt):
|
|
| 249 |
logger.warning("Using rule-based image generation")
|
| 250 |
return generate_rule_based_image(prompt)
|
| 251 |
|
| 252 |
-
#
|
| 253 |
def create_demo():
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
"a fantasy castle on a floating island"
|
| 275 |
-
],
|
| 276 |
-
inputs=prompt_input
|
| 277 |
-
)
|
| 278 |
-
|
| 279 |
-
# 输出区域
|
| 280 |
-
with gr.Column(scale=5):
|
| 281 |
-
output_image = gr.Image(label="Generated Image", type="pil")
|
| 282 |
-
|
| 283 |
-
# 绑定按钮事件
|
| 284 |
-
generate_button.click(
|
| 285 |
-
fn=generate_image,
|
| 286 |
-
inputs=prompt_input,
|
| 287 |
-
outputs=output_image
|
| 288 |
-
)
|
| 289 |
-
|
| 290 |
-
# 也绑定Enter键提交
|
| 291 |
-
prompt_input.submit(
|
| 292 |
-
fn=generate_image,
|
| 293 |
-
inputs=prompt_input,
|
| 294 |
-
outputs=output_image
|
| 295 |
-
)
|
| 296 |
|
| 297 |
return demo
|
| 298 |
|
|
@@ -305,7 +282,6 @@ if __name__ == "__main__":
|
|
| 305 |
logger.info("Starting Gradio interface...")
|
| 306 |
demo.launch(
|
| 307 |
server_name="0.0.0.0",
|
| 308 |
-
show_api=False,
|
| 309 |
share=False
|
| 310 |
)
|
| 311 |
except Exception as e:
|
|
|
|
| 111 |
model_id,
|
| 112 |
torch_dtype=torch_dtype,
|
| 113 |
use_auth_token=False, # 明确不使用认证
|
|
|
|
| 114 |
safety_checker=None, # 禁用安全检查器
|
| 115 |
)
|
| 116 |
pipe = pipe.to(device)
|
|
|
|
| 248 |
logger.warning("Using rule-based image generation")
|
| 249 |
return generate_rule_based_image(prompt)
|
| 250 |
|
| 251 |
+
# 为旧版 gradio 创建界面
|
| 252 |
def create_demo():
|
| 253 |
+
# 使用 Interface 替代 Blocks (兼容3.19.1)
|
| 254 |
+
demo = gr.Interface(
|
| 255 |
+
fn=generate_image,
|
| 256 |
+
inputs=gr.Textbox(
|
| 257 |
+
label="Prompt",
|
| 258 |
+
placeholder="Describe the image you want, e.g.: a cute cat, sunset over mountains...",
|
| 259 |
+
lines=2
|
| 260 |
+
),
|
| 261 |
+
outputs=gr.Image(label="Generated Image", type="pil"),
|
| 262 |
+
title="Text to Image Generator",
|
| 263 |
+
description="Enter a text description to generate an image.",
|
| 264 |
+
examples=[
|
| 265 |
+
"a cute cat sitting on a windowsill",
|
| 266 |
+
"beautiful sunset over mountains",
|
| 267 |
+
"an astronaut riding a horse in space",
|
| 268 |
+
"a fantasy castle on a floating island"
|
| 269 |
+
],
|
| 270 |
+
allow_flagging=False,
|
| 271 |
+
cache_examples=False
|
| 272 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
return demo
|
| 275 |
|
|
|
|
| 282 |
logger.info("Starting Gradio interface...")
|
| 283 |
demo.launch(
|
| 284 |
server_name="0.0.0.0",
|
|
|
|
| 285 |
share=False
|
| 286 |
)
|
| 287 |
except Exception as e:
|
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
accelerate==0.15.0
|
| 2 |
diffusers==0.10.2
|
| 3 |
-
huggingface-hub==0.
|
| 4 |
torch==1.13.1
|
| 5 |
transformers==4.25.1
|
| 6 |
safetensors==0.3.1
|
| 7 |
-
gradio==3.
|
| 8 |
Pillow==9.5.0
|
|
|
|
| 1 |
accelerate==0.15.0
|
| 2 |
diffusers==0.10.2
|
| 3 |
+
huggingface-hub==0.13.0
|
| 4 |
torch==1.13.1
|
| 5 |
transformers==4.25.1
|
| 6 |
safetensors==0.3.1
|
| 7 |
+
gradio==3.19.1
|
| 8 |
Pillow==9.5.0
|