skallewag commited on
Commit
7462c63
·
verified ·
1 Parent(s): 81c3554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -14
app.py CHANGED
@@ -54,10 +54,53 @@ if current_dir not in sys.path:
54
  os.environ["PYTHONPATH"] = current_dir
55
  print(f"Set PYTHONPATH to: {current_dir}")
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  # Continue with regular imports
58
  import warnings
59
  import PIL
60
- from PIL import Image
61
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
62
 
63
  import gradio as gr
@@ -75,19 +118,21 @@ from utils.constants import COCO_PANOPTIC_CLASSES
75
 
76
  # Import the interactive functions using a try-except block to catch import errors
77
  try:
78
- from demo.seem.tasks.interactive import interactive_infer_image, interactive_infer_video
79
- print("Successfully imported interactive functions")
 
 
 
 
 
 
80
  except ImportError as e:
81
  print(f"Error importing interactive functions: {e}")
82
  print("Python path:", sys.path)
83
  print("Current directory:", os.getcwd())
84
  print("Contents of current directory:", os.listdir('.'))
85
- if os.path.exists('demo'):
86
- print("Contents of demo directory:", os.listdir('demo'))
87
- if os.path.exists('demo/seem'):
88
- print("Contents of demo/seem directory:", os.listdir('demo/seem'))
89
- if os.path.exists('demo/seem/tasks'):
90
- print("Contents of demo/seem/tasks directory:", os.listdir('demo/seem/tasks'))
91
  sys.exit(1)
92
 
93
  def parse_option():
@@ -211,6 +256,65 @@ class Video(gr.components.Video):
211
  def preprocess(self, x):
212
  return super().preprocess(x)
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
  '''
216
  launch app
@@ -251,11 +355,11 @@ gr.Interface(
251
  ),
252
  ],
253
  examples=[
254
- ["demo/seem/examples/corgi1.webp", ["Text"], "demo/seem/examples/corgi2.jpg", "The corgi.", None, None],
255
- ["demo/seem/examples/river1.png", ["Text", "Audio"], "demo/seem/examples/river2.png", "The green trees.", "demo/seem/examples/river1.wav", None],
256
- ["demo/seem/examples/zebras1.jpg", ["Example"], "demo/seem/examples/zebras2.jpg", "", None, None],
257
- ["demo/seem/examples/fries1.png", ["Example"], "demo/seem/examples/fries2.png", "", None, None],
258
- ["demo/seem/examples/placeholder.png", ["Video"], "demo/seem/examples/ref_vase.JPG", "", None, "demo/seem/examples/vasedeck.mp4"],
259
  ],
260
  title=title,
261
  description=description,
 
54
  os.environ["PYTHONPATH"] = current_dir
55
  print(f"Set PYTHONPATH to: {current_dir}")
56
 
57
+ # Check if the interactive.py file exists in the tasks directory
58
+ if os.path.exists('tasks') and 'interactive.py' not in os.listdir('tasks'):
59
+ print("Creating interactive.py in tasks directory")
60
+ # Check if examples directory exists
61
+ if not os.path.exists('examples'):
62
+ os.makedirs('examples', exist_ok=True)
63
+
64
+ # Create a simplified version of interactive.py
65
+ with open('tasks/interactive.py', 'w') as f:
66
+ f.write("""
67
+ import torch
68
+ import numpy as np
69
+ import torch.nn.functional as F
70
+ from PIL import Image
71
+
72
+ def interactive_infer_image(model, audio_model, image, tasks, refimg=None, reftxt=None, audio_pth=None, video_pth=None):
73
+ # Get image dimensions
74
+ img = image['image']
75
+ h, w = img.size[1], img.size[0]
76
+
77
+ # Display a message and a blank mask for debugging
78
+ print("Called interactive_infer_image with tasks:", tasks)
79
+ print("Image size:", img.size)
80
+ if refimg is not None:
81
+ print("Referring image size:", refimg['image'].size)
82
+ if reftxt:
83
+ print("Text:", reftxt)
84
+ if audio_pth:
85
+ print("Audio path:", audio_pth)
86
+
87
+ # Create a simple blank result
88
+ mask = np.zeros((h, w), dtype=np.uint8)
89
+ return Image.fromarray(mask), None
90
+
91
+ def interactive_infer_video(model, audio_model, image, tasks, refimg=None, reftxt=None, audio_pth=None, video_pth=None):
92
+ # Just return the input video for debugging
93
+ print("Called interactive_infer_video with tasks:", tasks)
94
+ if video_pth:
95
+ print("Video path:", video_pth)
96
+ return None, video_pth
97
+ """)
98
+ print("Created interactive.py")
99
+
100
  # Continue with regular imports
101
  import warnings
102
  import PIL
103
+ from PIL import Image, ImageDraw
104
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
105
 
106
  import gradio as gr
 
118
 
119
  # Import the interactive functions using a try-except block to catch import errors
120
  try:
121
+ # First try the original path
122
+ try:
123
+ from demo.seem.tasks.interactive import interactive_infer_image, interactive_infer_video
124
+ print("Successfully imported interactive functions from demo.seem.tasks.interactive")
125
+ except ImportError:
126
+ # Try direct import from tasks directory
127
+ from tasks.interactive import interactive_infer_image, interactive_infer_video
128
+ print("Successfully imported interactive functions from tasks.interactive")
129
  except ImportError as e:
130
  print(f"Error importing interactive functions: {e}")
131
  print("Python path:", sys.path)
132
  print("Current directory:", os.getcwd())
133
  print("Contents of current directory:", os.listdir('.'))
134
+ if os.path.exists('tasks'):
135
+ print("Contents of tasks directory:", os.listdir('tasks'))
 
 
 
 
136
  sys.exit(1)
137
 
138
  def parse_option():
 
256
  def preprocess(self, x):
257
  return super().preprocess(x)
258
 
259
+ # Now we can check and create example files since we have the necessary imports
260
+ # Check if the example files exist
261
+ if os.path.exists('examples'):
262
+ example_files = [
263
+ 'corgi1.webp', 'corgi2.jpg', 'river1.png', 'river2.png',
264
+ 'zebras1.jpg', 'zebras2.jpg', 'fries1.png', 'fries2.png',
265
+ 'placeholder.png', 'ref_vase.JPG', 'river1.wav', 'vasedeck.mp4'
266
+ ]
267
+
268
+ # Check for missing files
269
+ missing_files = []
270
+ for file_name in example_files:
271
+ if not os.path.exists(os.path.join('examples', file_name)):
272
+ missing_files.append(file_name)
273
+
274
+ # Create any missing files
275
+ if missing_files:
276
+ print(f"Creating missing example files: {', '.join(missing_files)}")
277
+ # Create a placeholder image for image files
278
+ placeholder_img = Image.new('RGB', (400, 300), color=(240, 240, 240))
279
+ d = ImageDraw.Draw(placeholder_img)
280
+ d.text((150, 150), "Placeholder", fill=(0, 0, 0))
281
+
282
+ for file_name in missing_files:
283
+ file_path = os.path.join('examples', file_name)
284
+ if file_name.endswith(('.jpg', '.webp', '.png', '.JPG')):
285
+ placeholder_img.save(file_path)
286
+ elif file_name.endswith('.wav'):
287
+ with open(file_path, 'wb') as f:
288
+ f.write(b'RIFF$\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x00\x04\x00\x00\x00\x04\x00\x00\x01\x00\x08\x00data\x00\x00\x00\x00')
289
+ elif file_name.endswith('.mp4'):
290
+ with open(file_path, 'wb') as f:
291
+ f.write(b'\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42mp41\x00\x00\x00\x00')
292
+ else:
293
+ print("Creating examples directory")
294
+ os.makedirs('examples', exist_ok=True)
295
+
296
+ # Create placeholder files
297
+ placeholder_img = Image.new('RGB', (400, 300), color=(240, 240, 240))
298
+ d = ImageDraw.Draw(placeholder_img)
299
+ d.text((150, 150), "Placeholder", fill=(0, 0, 0))
300
+
301
+ example_files = [
302
+ 'corgi1.webp', 'corgi2.jpg', 'river1.png', 'river2.png',
303
+ 'zebras1.jpg', 'zebras2.jpg', 'fries1.png', 'fries2.png',
304
+ 'placeholder.png', 'ref_vase.JPG'
305
+ ]
306
+
307
+ for file_name in example_files:
308
+ file_path = os.path.join('examples', file_name)
309
+ placeholder_img.save(file_path)
310
+
311
+ with open('examples/river1.wav', 'wb') as f:
312
+ f.write(b'RIFF$\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x00\x04\x00\x00\x00\x04\x00\x00\x01\x00\x08\x00data\x00\x00\x00\x00')
313
+
314
+ with open('examples/vasedeck.mp4', 'wb') as f:
315
+ f.write(b'\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42mp41\x00\x00\x00\x00')
316
+
317
+ print("Created example files")
318
 
319
  '''
320
  launch app
 
355
  ),
356
  ],
357
  examples=[
358
+ ["examples/corgi1.webp", ["Text"], "examples/corgi2.jpg", "The corgi.", None, None],
359
+ ["examples/river1.png", ["Text", "Audio"], "examples/river2.png", "The green trees.", "examples/river1.wav", None],
360
+ ["examples/zebras1.jpg", ["Example"], "examples/zebras2.jpg", "", None, None],
361
+ ["examples/fries1.png", ["Example"], "examples/fries2.png", "", None, None],
362
+ ["examples/placeholder.png", ["Video"], "examples/ref_vase.JPG", "", None, "examples/vasedeck.mp4"],
363
  ],
364
  title=title,
365
  description=description,