Ifeanyi commited on
Commit
8fd768e
·
verified ·
1 Parent(s): a34aece

Update script.py

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