SPACERUNNER99 commited on
Commit
fb7175b
·
verified ·
1 Parent(s): f779c4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -13,6 +13,7 @@ from moviepy import VideoFileClip, TextClip, CompositeVideoClip, AudioFileClip,
13
  import pysrt
14
  import instaloader
15
  import time
 
16
  import concurrent.futures
17
  api_key = "268976:66f4f58a2a905"
18
 
@@ -288,21 +289,13 @@ def clean_text(text):
288
  text = re.sub(r'^srt', '', text, flags=re.MULTILINE)
289
  return text
290
 
291
- def enhance_text(api_key, text, google):
292
  url = "https://api.one-api.ir/chatbot/v1/gpt4o/"
293
 
294
  # Prepare the request body
295
  request_body = [{
296
  "role": "user",
297
- "content": f" i have a main English text that has been translated, use the main text and the translations to write a better translation of the main text in persian. main text: {text}. in response dont add anything and only return the translation will keeping the srt format"
298
- },
299
- {
300
- "role": "assistant",
301
- "content": "ok"
302
- },
303
- {
304
- "role": "user",
305
- "content": f"tarnslation: {google} in response only return the better version of the translation will maintaining the srt format of the text"
306
  },]
307
 
308
  # Add the API key to the request
@@ -388,7 +381,7 @@ def process_video(url, type):
388
  source_language = "en"
389
  target_language = "fa"
390
  srt_string = read_srt_file(subtitle_file)
391
- google_translate = translate_text(api_key, source_language, target_language, srt_string)
392
  write_google(google_translate)
393
  srt = read_srt_file("google_translate.srt")
394
  return srt, input_video
 
13
  import pysrt
14
  import instaloader
15
  import time
16
+ import re
17
  import concurrent.futures
18
  api_key = "268976:66f4f58a2a905"
19
 
 
289
  text = re.sub(r'^srt', '', text, flags=re.MULTILINE)
290
  return text
291
 
292
+ def enhance_text(api_key, text):
293
  url = "https://api.one-api.ir/chatbot/v1/gpt4o/"
294
 
295
  # Prepare the request body
296
  request_body = [{
297
  "role": "user",
298
+ "content": f"{text} Translate the above text into Persian, converting the English terms used in it into common Persian terms. in respose dont add any thing exept for the srt formated translation."
 
 
 
 
 
 
 
 
299
  },]
300
 
301
  # Add the API key to the request
 
381
  source_language = "en"
382
  target_language = "fa"
383
  srt_string = read_srt_file(subtitle_file)
384
+ google_translate = enhance_text(api_key, srt_string)
385
  write_google(google_translate)
386
  srt = read_srt_file("google_translate.srt")
387
  return srt, input_video