rsax commited on
Commit
0d780bd
·
verified ·
1 Parent(s): fc419c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -74,38 +74,24 @@ def infer(text):
74
  raise ValueError("Generated motion data is empty")
75
 
76
  gif_bytes = draw_to_batch([motion_data], [text], None)
77
-
78
- # Ensure the directory exists in the current working directory
79
- dir_path = "animation"
80
- if not os.path.exists(dir_path):
81
- os.makedirs(dir_path)
82
-
83
- persistent_gif_path = os.path.join(dir_path, "animation.gif")
84
- with open(persistent_gif_path, "wb") as f:
85
- f.write(gif_bytes)
86
 
87
- file_size = os.path.getsize(persistent_gif_path)
88
- print(f"Saved GIF to {persistent_gif_path}, file size: {file_size} bytes")
89
- if file_size <= 0:
90
- raise ValueError("Generated GIF is empty")
91
- if not os.path.exists(persistent_gif_path):
92
- print(f"Error: GIF not saved to {persistent_gif_path}")
93
- else:
94
- print(f"GIF saved successfully to {persistent_gif_path}")
95
 
96
- return persistent_gif_path
97
 
98
  with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
99
  with gr.Column():
100
- gr.Markdown("## 3D Human Motion" + ("Generation" if device == "cuda" else "CPU"))
101
  text_input = gr.Textbox(label="Enter the human action to generate", placeholder="Enter text description for the action here...")
102
- output_image = gr.Image(label="Generated Human Motion", type='filepath')
103
  submit_button = gr.Button("Generate Motion")
104
 
105
  submit_button.click(
106
  fn=infer,
107
  inputs=[text_input],
108
- outputs=[output_image]
109
  )
110
 
111
  if __name__ == "__main__":
 
74
  raise ValueError("Generated motion data is empty")
75
 
76
  gif_bytes = draw_to_batch([motion_data], [text], None)
 
 
 
 
 
 
 
 
 
77
 
78
+ # Encode the GIF bytes to a base64 string
79
+ gif_base64 = base64.b64encode(gif_bytes).decode('ascii')
80
+ gif_html = f'<img src="data:image/gif;base64,{gif_base64}" />'
 
 
 
 
 
81
 
82
+ return gif_html
83
 
84
  with gr.Blocks(css=".container { max-width: 800px; margin: auto; }") as demo:
85
  with gr.Column():
86
+ gr.Markdown("## 3D Human Motion Generation")
87
  text_input = gr.Textbox(label="Enter the human action to generate", placeholder="Enter text description for the action here...")
88
+ output_html = gr.HTML(label="Generated Human Motion")
89
  submit_button = gr.Button("Generate Motion")
90
 
91
  submit_button.click(
92
  fn=infer,
93
  inputs=[text_input],
94
+ outputs=[output_html]
95
  )
96
 
97
  if __name__ == "__main__":