ygauravyy commited on
Commit
0cd678c
1 Parent(s): 29c746e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -10,10 +10,6 @@ OUTPUT_FOLDER = 'outputs_gradio'
10
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
11
  os.makedirs(OUTPUT_FOLDER, exist_ok=True)
12
 
13
- # Create flagged directory inside outputs_gradio to avoid permission issues
14
- FLAGGED_DIR = os.path.join(OUTPUT_FOLDER, 'flagged')
15
- os.makedirs(FLAGGED_DIR, exist_ok=True)
16
-
17
  def animate_image(file_path):
18
  """
19
  Function to process the uploaded image and generate an animated GIF.
@@ -27,26 +23,28 @@ def animate_image(file_path):
27
  if not file_path:
28
  raise ValueError("No file uploaded.")
29
 
 
30
  input_path = file_path
31
  filename = os.path.basename(input_path)
32
  base, ext = os.path.splitext(filename)
33
 
34
- # Validate file extension
35
- allowed_extensions = ['.png', '.jpg', '.jpeg', '.bmp']
36
- if ext.lower() not in allowed_extensions:
37
- raise ValueError("Unsupported file type. Please upload an image file (png, jpg, jpeg, bmp).")
38
-
39
  # Define the annotation directory for this specific image
40
  char_anno_dir = os.path.join(OUTPUT_FOLDER, f"{base}_out")
41
  os.makedirs(char_anno_dir, exist_ok=True)
42
 
43
  try:
44
- # Run the image_to_animation.py script
 
 
 
 
 
45
  subprocess.run([
46
  'python', 'examples/image_to_animation.py',
47
  input_path, char_anno_dir
 
48
  ], check=True)
49
-
50
  # Path to the generated GIF
51
  gif_path = os.path.join(char_anno_dir, "video.gif")
52
 
@@ -60,16 +58,14 @@ def animate_image(file_path):
60
  except Exception as e:
61
  raise RuntimeError(f"Unexpected error: {e}")
62
 
63
- # Create the Gradio interface
64
  iface = gr.Interface(
65
  fn=animate_image,
66
  inputs=gr.Image(label="Upload Drawing", type="filepath", sources=["upload", "webcam"]),
67
  outputs=gr.Image(label="Animated GIF"),
68
  title="Animated Drawings",
69
- description="Upload your drawing or take a photo, and get an animated GIF.",
70
- flagging_dir=FLAGGED_DIR
71
  )
72
 
73
  if __name__ == "__main__":
74
- # Listen on 0.0.0.0:7860 (default for Hugging Face Spaces)
75
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
10
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
11
  os.makedirs(OUTPUT_FOLDER, exist_ok=True)
12
 
 
 
 
 
13
  def animate_image(file_path):
14
  """
15
  Function to process the uploaded image and generate an animated GIF.
 
23
  if not file_path:
24
  raise ValueError("No file uploaded.")
25
 
26
+ # 'file_path' is a string path to the uploaded file
27
  input_path = file_path
28
  filename = os.path.basename(input_path)
29
  base, ext = os.path.splitext(filename)
30
 
 
 
 
 
 
31
  # Define the annotation directory for this specific image
32
  char_anno_dir = os.path.join(OUTPUT_FOLDER, f"{base}_out")
33
  os.makedirs(char_anno_dir, exist_ok=True)
34
 
35
  try:
36
+ # Validate file extension
37
+ allowed_extensions = ['.png', '.jpg', '.jpeg', '.bmp']
38
+ if ext.lower() not in allowed_extensions:
39
+ raise ValueError("Unsupported file type. Please upload an image file (png, jpg, jpeg, bmp).")
40
+
41
+ # Run the image_to_animation.py script with required arguments
42
  subprocess.run([
43
  'python', 'examples/image_to_animation.py',
44
  input_path, char_anno_dir
45
+ # Optionally, add motion_cfg_fn and retarget_cfg_fn here if needed
46
  ], check=True)
47
+
48
  # Path to the generated GIF
49
  gif_path = os.path.join(char_anno_dir, "video.gif")
50
 
 
58
  except Exception as e:
59
  raise RuntimeError(f"Unexpected error: {e}")
60
 
61
+ # Define the Gradio interface using the updated API
62
  iface = gr.Interface(
63
  fn=animate_image,
64
  inputs=gr.Image(label="Upload Drawing", type="filepath", sources=["upload", "webcam"]),
65
  outputs=gr.Image(label="Animated GIF"),
66
  title="Animated Drawings",
67
+ description="Upload your drawing or take a photo, and get an animated GIF."
 
68
  )
69
 
70
  if __name__ == "__main__":
71
+ iface.launch()