Salman11223 commited on
Commit
58110bd
1 Parent(s): f3dee0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -12
app.py CHANGED
@@ -1,19 +1,24 @@
1
  from translate import Translate # Import the Translate class
2
  import gradio as gr
3
-
4
  import os
5
- import moviepy.editor as mp
6
- import assemblyai as aai
7
- import requests
8
- import azure.cognitiveservices.speech as speechsdk
9
- from moviepy.editor import AudioFileClip
10
- from gradio_client import Client
11
-
12
- def app(video_path,original_language, target_language):
13
- translator = Translate(video_path,original_language, target_language)
14
  translated_text_file = translator.transcribe_and_translate()
15
- return translated_text_file
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  interface_text_file = gr.Interface(
18
  fn=app,
19
  inputs=[
@@ -21,7 +26,7 @@ interface_text_file = gr.Interface(
21
  gr.Dropdown(["English", "German", "French", "Spanish"], label="Original Language"),
22
  gr.Dropdown(["English", "German", "French", "Spanish", "Urdu"], label="Targeted Language"),
23
  ],
24
- outputs=[gr.File(label="Translated Text File")],
25
  )
26
 
27
  interface_text_file.launch(debug=True)
@@ -39,6 +44,68 @@ interface_text_file.launch(debug=True)
39
 
40
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # interface = gr.Interface(
43
  # fn=app,
44
  # inputs=[
 
1
  from translate import Translate # Import the Translate class
2
  import gradio as gr
 
3
  import os
4
+
5
+ def app(video_path, original_language, target_language):
6
+ translator = Translate(video_path, original_language, target_language)
 
 
 
 
 
 
7
  translated_text_file = translator.transcribe_and_translate()
 
8
 
9
+ # Save the file with the desired name, ensuring a unique name if needed
10
+ saved_file_path = "translated_text.txt" # Replace with your preferred filename
11
+ if os.path.exists(saved_file_path):
12
+ base, ext = os.path.splitext(saved_file_path)
13
+ counter = 1
14
+ while os.path.exists(f"{base}_{counter}{ext}"):
15
+ counter += 1
16
+ saved_file_path = f"{base}_{counter}{ext}"
17
+ os.rename(translated_text_file, saved_file_path)
18
+
19
+ return saved_file_path
20
+
21
+ # Gradio's built-in File component handles download functionality
22
  interface_text_file = gr.Interface(
23
  fn=app,
24
  inputs=[
 
26
  gr.Dropdown(["English", "German", "French", "Spanish"], label="Original Language"),
27
  gr.Dropdown(["English", "German", "French", "Spanish", "Urdu"], label="Targeted Language"),
28
  ],
29
+ outputs=gr.File(label="Translated Text File"), # Gradio provides the download link
30
  )
31
 
32
  interface_text_file.launch(debug=True)
 
44
 
45
 
46
 
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+ # import gradio as gr
70
+
71
+ # import os
72
+ # import moviepy.editor as mp
73
+ # import assemblyai as aai
74
+ # import requests
75
+ # import azure.cognitiveservices.speech as speechsdk
76
+ # from moviepy.editor import AudioFileClip
77
+ # from gradio_client import Client
78
+
79
+ # def app(video_path,original_language, target_language):
80
+ # translator = Translate(video_path,original_language, target_language)
81
+ # translated_text_file = translator.transcribe_and_translate()
82
+ # return translated_text_file
83
+
84
+ # interface_text_file = gr.Interface(
85
+ # fn=app,
86
+ # inputs=[
87
+ # gr.File(label="Upload Text File"),
88
+ # gr.Dropdown(["English", "German", "French", "Spanish"], label="Original Language"),
89
+ # gr.Dropdown(["English", "German", "French", "Spanish", "Urdu"], label="Targeted Language"),
90
+ # ],
91
+ # outputs=[gr.File(label="Translated Text File")],
92
+ # )
93
+
94
+ # interface_text_file.launch(debug=True)
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
  # interface = gr.Interface(
110
  # fn=app,
111
  # inputs=[