sreepathi-ravikumar commited on
Commit
2f55002
·
verified ·
1 Parent(s): 6b8f746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -28
app.py CHANGED
@@ -16,10 +16,10 @@ app = Flask(__name__)
16
  SAVE_DIR = "/app/data/video/"
17
  os.makedirs(SAVE_DIR, exist_ok=True)
18
 
19
- def send_request_to_space(id,lines,url):
20
  payload = {
21
  "id": id,
22
- "lines": lines # or [line] depending on your expected payload
23
  }
24
 
25
  try:
@@ -122,33 +122,10 @@ def generate_video():
122
  return send_file(video_link, mimetype='video/mp4')
123
  else:
124
  space_b_url = ['https://sreepathi-ravikumar-subprocess1.hf.space/generate', 'https://sreepathi-ravikumar-subprocess2.hf.space/generate', 'https://sreepathi-ravikumar-subprocess3.hf.space/generate', 'https://sreepathi-ravikumar-subprocess4.hf.space/generate', 'https://sreepathi-ravikumar-subprocess5.hf.space/generate', 'https://sreepathi-ravikumar-subprocess6.hf.space/generate', 'https://sreepathi-ravikumar-subprocess7.hf.space/generate', 'https://sreepathi-ravikumar-subprocess8.hf.space/generate', 'https://sreepathi-ravikumar-subprocess9.hf.space/generate', 'https://sreepathi-ravikumar-subprocess10.hf.space/generate']
125
- for id in range(len(lines)):
126
- payload = {
127
- "id": id,
128
- "lines": lines
129
- }
130
-
131
- # Replace with your actual Space B URL
132
-
133
-
134
- response = requests.post(space_b_url[id+1], json=payload)
135
-
136
- if response.status_code == 200:
137
- # Save received video file
138
- with open(f"/app/data/video/clip{id}.mp4", "wb") as f:
139
- f.write(response.content)
140
- else:
141
- raise Exception(f"Error from Space B: {response.text}")
142
 
143
- with ThreadPoolExecutor(max_workers=10) as executor:
144
- for id, line in enumerate(lines):
145
- url = space_b_urls[id % len(space_b_urls)] # reuse if more lines than URLs
146
- futures.append(executor.submit(send_request_to_space, id, lines, url))
147
-
148
- for future in as_completed(futures):
149
- result = future.result()
150
- if result:
151
- video_paths.append(result)
152
 
153
  video_path = video_com(lines)
154
  #for img in image_files:
 
16
  SAVE_DIR = "/app/data/video/"
17
  os.makedirs(SAVE_DIR, exist_ok=True)
18
 
19
+ def send_task(id,url,lines):
20
  payload = {
21
  "id": id,
22
+ "lines": lines
23
  }
24
 
25
  try:
 
122
  return send_file(video_link, mimetype='video/mp4')
123
  else:
124
  space_b_url = ['https://sreepathi-ravikumar-subprocess1.hf.space/generate', 'https://sreepathi-ravikumar-subprocess2.hf.space/generate', 'https://sreepathi-ravikumar-subprocess3.hf.space/generate', 'https://sreepathi-ravikumar-subprocess4.hf.space/generate', 'https://sreepathi-ravikumar-subprocess5.hf.space/generate', 'https://sreepathi-ravikumar-subprocess6.hf.space/generate', 'https://sreepathi-ravikumar-subprocess7.hf.space/generate', 'https://sreepathi-ravikumar-subprocess8.hf.space/generate', 'https://sreepathi-ravikumar-subprocess9.hf.space/generate', 'https://sreepathi-ravikumar-subprocess10.hf.space/generate']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ with ThreadPoolExecutor(max_workers=len(lines)) as executor:
127
+ for id in range(len(lines)):
128
+ executor.submit(send_task,id,space_b_url[id],lines)
 
 
 
 
 
 
129
 
130
  video_path = video_com(lines)
131
  #for img in image_files: