Update app.py
Browse files
app.py
CHANGED
@@ -281,6 +281,13 @@ def read_srt_file(file_path):
|
|
281 |
except Exception as e:
|
282 |
print(f"An error occurred: {e}")
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
def enhance_text(api_key, text, google):
|
285 |
url = "https://api.one-api.ir/chatbot/v1/gpt4o/"
|
286 |
|
@@ -302,9 +309,11 @@ def enhance_text(api_key, text, google):
|
|
302 |
# Check the response status
|
303 |
if response.status_code == 200:
|
304 |
result = response.json()
|
|
|
|
|
305 |
print("result: ")
|
306 |
-
print(
|
307 |
-
return
|
308 |
else:
|
309 |
print(f"Error: {response.status_code}, {response.text}")
|
310 |
return None
|
@@ -343,7 +352,7 @@ def create_subtitle_clips(subtitles, videosize, fontsize, font, color, debug):
|
|
343 |
#bidi_text = get_display(reshaped_text)
|
344 |
text_clip = TextClip(font, subtitle.text, font_size=fontsize, size=(int(video_width * 0.8), int(video_height * 0.2)) ,text_align="center" ,color=color, bg_color='black', method='caption').with_start(start_time).with_duration(duration)
|
345 |
subtitle_x_position = 'center'
|
346 |
-
subtitle_y_position = video_height * 0.
|
347 |
text_position = (subtitle_x_position, subtitle_y_position)
|
348 |
subtitle_clips.append(text_clip.with_position(text_position))
|
349 |
return subtitle_clips
|
|
|
281 |
except Exception as e:
|
282 |
print(f"An error occurred: {e}")
|
283 |
|
284 |
+
def clean_text(text):
|
285 |
+
# Remove 'srt ' from the start
|
286 |
+
text = re.sub(r'^srt ', '', text, flags=re.MULTILINE)
|
287 |
+
# Remove ''' from the start and end
|
288 |
+
text = re.sub(r"^'''|'''$", '', text)
|
289 |
+
return text
|
290 |
+
|
291 |
def enhance_text(api_key, text, google):
|
292 |
url = "https://api.one-api.ir/chatbot/v1/gpt4o/"
|
293 |
|
|
|
309 |
# Check the response status
|
310 |
if response.status_code == 200:
|
311 |
result = response.json()
|
312 |
+
clean_text(result["result"][0])
|
313 |
+
last = clean_text(result["result"][0])
|
314 |
print("result: ")
|
315 |
+
print(last)
|
316 |
+
return last
|
317 |
else:
|
318 |
print(f"Error: {response.status_code}, {response.text}")
|
319 |
return None
|
|
|
352 |
#bidi_text = get_display(reshaped_text)
|
353 |
text_clip = TextClip(font, subtitle.text, font_size=fontsize, size=(int(video_width * 0.8), int(video_height * 0.2)) ,text_align="center" ,color=color, bg_color='black', method='caption').with_start(start_time).with_duration(duration)
|
354 |
subtitle_x_position = 'center'
|
355 |
+
subtitle_y_position = video_height * 0.74
|
356 |
text_position = (subtitle_x_position, subtitle_y_position)
|
357 |
subtitle_clips.append(text_clip.with_position(text_position))
|
358 |
return subtitle_clips
|