Baggio200cn commited on
Commit
18c3f36
·
verified ·
1 Parent(s): d1e7a08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,12 +1,15 @@
 
1
  import gradio as gr
2
  from huggingface_hub import snapshot_download
3
- import os
4
  import torch
5
  from diffusers import FluxPipeline
6
 
7
- # 下载模型 (Space 启动时自动跑)
 
 
 
8
  model_dir = "models/postercraft/postercraft_rl"
9
- snapshot_download(repo_id="PosterCraft/PosterCraft-v1_RL", local_dir=model_dir, resume_download=True)
10
 
11
  # 加载模型
12
  pipe = FluxPipeline.from_pretrained(model_dir)
@@ -14,8 +17,11 @@
14
 
15
  # 生成函数
16
  def generate_poster(prompt):
17
- image = pipe(prompt).images[0]
18
- return image
 
 
 
19
 
20
  # Gradio UI
21
  iface = gr.Interface(
 
1
+ import os
2
  import gradio as gr
3
  from huggingface_hub import snapshot_download
 
4
  import torch
5
  from diffusers import FluxPipeline
6
 
7
+ # 安装依赖 (Space 启动时自动跑)
8
+ os.system("pip install huggingface-hub transformers diffusers accelerate safetensors torch gradio")
9
+
10
+ # 下载模型
11
  model_dir = "models/postercraft/postercraft_rl"
12
+ snapshot_download(repo_id="PosterCraft/PosterCraft-v1_RL", local_dir=model_dir, resume_download=True, token=os.environ.get("HF_TOKEN")) # 加 Token 支持
13
 
14
  # 加载模型
15
  pipe = FluxPipeline.from_pretrained(model_dir)
 
17
 
18
  # 生成函数
19
  def generate_poster(prompt):
20
+ try:
21
+ image = pipe(prompt).images[0]
22
+ return image
23
+ except Exception as e:
24
+ return f"Error: {str(e)}" # 错误处理
25
 
26
  # Gradio UI
27
  iface = gr.Interface(