BestWishYsh commited on
Commit
ded9e79
·
verified ·
1 Parent(s): 57dd52c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -4,6 +4,7 @@ import copy
4
  import time
5
  import torch
6
  import random
 
7
  import gradio as gr
8
  from glob import glob
9
  from omegaconf import OmegaConf
@@ -76,7 +77,6 @@ os.system(f"rm -rf gradio_cached_examples/")
76
  device = "cuda"
77
 
78
  def random_seed():
79
- # 修复:转成字符串以匹配 Textbox 组件的预期输入类型
80
  return str(random.randint(1, 10**16))
81
 
82
  class MagicTimeController:
@@ -227,11 +227,14 @@ class MagicTimeController:
227
  "dreambooth": dreambooth_dropdown,
228
  }
229
 
 
 
 
230
  torch.cuda.empty_cache()
231
  time.sleep(1)
232
 
233
- # 修复:直接返回文件路径和典,不要返回包裹的 gr 组件对象
234
- return save_sample_path, json_config
235
 
236
  controller = MagicTimeController()
237
 
@@ -239,7 +242,7 @@ def ui():
239
  with gr.Blocks(css=css) as demo:
240
  gr.HTML("""
241
  <div style='display: flex; align-items: center; justify-content: center; text-align: center;'>
242
- <img src='https://raw.githubusercontent.com/SHYuanBest/shyuanbest_media/main/MagicTime/MagicTime_logo.png' style='width: 300px; height: auto; margin-right: 10px;' />
243
  </div>
244
  """)
245
  gr.Markdown(
@@ -271,7 +274,9 @@ def ui():
271
 
272
  with gr.Column():
273
  result_video = gr.Video(label="Generated Animation", interactive=False)
274
- json_config = gr.Json(label="Config", value={})
 
 
275
 
276
  inputs = [dreambooth_dropdown, motion_module_dropdown, prompt_textbox, negative_prompt_textbox, width_slider, height_slider, seed_textbox]
277
  outputs = [result_video, json_config]
@@ -290,4 +295,5 @@ def ui():
290
  if __name__ == "__main__":
291
  demo = ui()
292
  demo.queue(max_size=20)
293
- demo.launch(share=True) # share=True 用于创建公开链接
 
 
4
  import time
5
  import torch
6
  import random
7
+ import json # 新增:用于将字典转为字符串
8
  import gradio as gr
9
  from glob import glob
10
  from omegaconf import OmegaConf
 
77
  device = "cuda"
78
 
79
  def random_seed():
 
80
  return str(random.randint(1, 10**16))
81
 
82
  class MagicTimeController:
 
227
  "dreambooth": dreambooth_dropdown,
228
  }
229
 
230
+ # 修复:将字典序列化为 JSON 字符串
231
+ json_config_str = json.dumps(json_config, indent=4)
232
+
233
  torch.cuda.empty_cache()
234
  time.sleep(1)
235
 
236
+ # 修复:直接返回字符串以配合 gr.Code 组件
237
+ return save_sample_path, json_config_str
238
 
239
  controller = MagicTimeController()
240
 
 
242
  with gr.Blocks(css=css) as demo:
243
  gr.HTML("""
244
  <div style='display: flex; align-items: center; justify-content: center; text-align: center;'>
245
+ <img src='https://raw.githubusercontent.com/SHYuanBest/shyuanbest_media/main/MagicTime/MagicTime_logo.png' style='width: 200px; height: auto; margin-right: 10px;' />
246
  </div>
247
  """)
248
  gr.Markdown(
 
274
 
275
  with gr.Column():
276
  result_video = gr.Video(label="Generated Animation", interactive=False)
277
+
278
+ # 修复:改用 gr.Code 接收字符串并以 JSON 格式高亮,绕过字典解析 Bug
279
+ json_config = gr.Code(label="Config", language="json", interactive=False)
280
 
281
  inputs = [dreambooth_dropdown, motion_module_dropdown, prompt_textbox, negative_prompt_textbox, width_slider, height_slider, seed_textbox]
282
  outputs = [result_video, json_config]
 
295
  if __name__ == "__main__":
296
  demo = ui()
297
  demo.queue(max_size=20)
298
+ # 修复:在 HF Spaces 去掉 share=True 避免警告和潜在的网络冲突
299
+ demo.launch()