Spaces:
Sleeping
Sleeping
Update script.py
Browse files
script.py
CHANGED
@@ -1,92 +1,95 @@
|
|
1 |
-
import assemblyai as aai
|
2 |
-
import google.generativeai as genai
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
1 |
+
import assemblyai as aai
|
2 |
+
import google.generativeai as genai
|
3 |
+
import os
|
4 |
+
|
5 |
+
def audioTranscribe(audio_file,translation):
|
6 |
+
gemini_api_key = os.getenv(GEMINI_API_KEY)
|
7 |
+
genai.configure(api_key=gemini_api_key)
|
8 |
+
|
9 |
+
model = genai.GenerativeModel("gemini-1.5-pro-002")
|
10 |
+
|
11 |
+
aai_api_key = os.getenv(ASSEMBLYAI_API_KEY)
|
12 |
+
aai.settings.api_key = aai_api_key
|
13 |
+
|
14 |
+
transcriber = aai.Transcriber()
|
15 |
+
transcript = transcriber.transcribe(audio_file)
|
16 |
+
|
17 |
+
if translation == "French":
|
18 |
+
|
19 |
+
prompt = "I want you to simply translate this text into French. Do not elaborate on the text."
|
20 |
+
|
21 |
+
response = model.generate_content([transcript.text,prompt])
|
22 |
+
|
23 |
+
elif translation == "Spanish":
|
24 |
+
prompt = "I want you to simply translate this text into Spanish. Do not elaborate on the text"
|
25 |
+
|
26 |
+
response = model.generate_content([transcript.text,prompt])
|
27 |
+
|
28 |
+
elif translation == "German":
|
29 |
+
prompt = "I want you to simply translate this text into German. Do not elaborate on the text."
|
30 |
+
|
31 |
+
response = model.generate_content([transcript.text,prompt])
|
32 |
+
|
33 |
+
elif translation == "Italian":
|
34 |
+
prompt = "I want you to simply translate this text into Italian. Do not elaborate on the text."
|
35 |
+
|
36 |
+
response = model.generate_content([transcript.text,prompt])
|
37 |
+
|
38 |
+
elif translation == "Japanese":
|
39 |
+
prompt = "I want you to simply translate this text into Japanese. Do not elaborate on the text."
|
40 |
+
|
41 |
+
response = model.generate_content([transcript.text,prompt])
|
42 |
+
|
43 |
+
elif translation == "Portuguese":
|
44 |
+
prompt = "I want you to simply translate this text into Portuguese. Do not elaborate on the text."
|
45 |
+
|
46 |
+
response = model.generate_content([transcript.text,prompt])
|
47 |
+
|
48 |
+
elif translation == "Dutch":
|
49 |
+
prompt = "I want you to simply translate this text into Dutch. Do not elaborate on the text."
|
50 |
+
|
51 |
+
response = model.generate_content([transcript.text,prompt])
|
52 |
+
|
53 |
+
elif translation == "Korean":
|
54 |
+
prompt = "I want you to simply translate this text into Korean. Do not elaborate on the text."
|
55 |
+
|
56 |
+
response = model.generate_content([transcript.text,prompt])
|
57 |
+
|
58 |
+
elif translation == "Hindi":
|
59 |
+
prompt = "I want you to simply translate this text into Hindi. Do not elaborate on the text."
|
60 |
+
|
61 |
+
response = model.generate_content([transcript.text,prompt])
|
62 |
+
|
63 |
+
elif translation == "Igbo":
|
64 |
+
prompt = "I want you to simply translate this text into Igbo. Do not elaborate on the text."
|
65 |
+
|
66 |
+
response = model.generate_content([transcript.text,prompt])
|
67 |
+
|
68 |
+
elif translation == "Yoruba":
|
69 |
+
prompt = "I want you to simply translate this text into Yoruba. Do not elaborate on the text."
|
70 |
+
|
71 |
+
response = model.generate_content([transcript.text,prompt])
|
72 |
+
|
73 |
+
elif translation == "Polish":
|
74 |
+
prompt = "I want you to simply translate this text into Polish. Do not elaborate on the text."
|
75 |
+
|
76 |
+
response = model.generate_content([transcript.text,prompt])
|
77 |
+
|
78 |
+
elif translation == "Swahili":
|
79 |
+
prompt = "I want you to simply translate this text into Swahili. Do not elaborate on the text."
|
80 |
+
|
81 |
+
response = model.generate_content([transcript.text,prompt])
|
82 |
+
|
83 |
+
elif translation == "Turkish":
|
84 |
+
prompt = "I want you to simply translate this text into Turkish. Do not elaborate on the text."
|
85 |
+
|
86 |
+
response = model.generate_content([transcript.text,prompt])
|
87 |
+
|
88 |
+
elif translation == "Hausa":
|
89 |
+
prompt = "I want you to simply translate this text into Hausa. Do not elaborate on the text."
|
90 |
+
|
91 |
+
response = model.generate_content([transcript.text,prompt])
|
92 |
+
|
93 |
+
|
94 |
+
return [transcript.text, response.text]
|
95 |
+
|