bahakizil commited on
Commit
0c32c01
·
verified ·
1 Parent(s): f6ebf70

Upload 2 files

Browse files
Files changed (2) hide show
  1. requirements.txt +126 -0
  2. translate_ai.py +116 -0
requirements.txt ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.3.0
3
+ altgraph @ file:///home/conda/feedstock_root/build_artifacts/altgraph_1695642967802/work
4
+ annotated-types==0.7.0
5
+ anyio==4.4.0
6
+ archspec @ file:///home/conda/feedstock_root/build_artifacts/archspec_1699370045702/work
7
+ assemblyai==0.28.1
8
+ attrs==23.2.0
9
+ boltons @ file:///home/conda/feedstock_root/build_artifacts/boltons_1703154663129/work
10
+ Brotli @ file:///Users/runner/miniforge3/conda-bld/brotli-split_1695989934239/work
11
+ certifi @ file:///home/conda/feedstock_root/build_artifacts/certifi_1718025014955/work/certifi
12
+ cffi @ file:///Users/runner/miniforge3/conda-bld/cffi_1696001737800/work
13
+ charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1698833585322/work
14
+ click==8.1.7
15
+ colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1666700638685/work
16
+ conda @ file:///Users/runner/miniforge3/conda-bld/conda_1701731166956/work
17
+ conda-libmamba-solver @ file:///home/conda/feedstock_root/build_artifacts/conda-libmamba-solver_1702406360642/work/src
18
+ conda-package-handling @ file:///home/conda/feedstock_root/build_artifacts/conda-package-handling_1691048088238/work
19
+ conda_package_streaming @ file:///home/conda/feedstock_root/build_artifacts/conda-package-streaming_1691009212940/work
20
+ contourpy @ file:///Users/runner/miniforge3/conda-bld/contourpy_1712429964190/work
21
+ cycler @ file:///home/conda/feedstock_root/build_artifacts/cycler_1696677705766/work
22
+ defusedxml @ file:///home/conda/feedstock_root/build_artifacts/defusedxml_1615232257335/work
23
+ distro @ file:///home/conda/feedstock_root/build_artifacts/distro_1675116244235/work
24
+ dnspython==2.6.1
25
+ email_validator==2.2.0
26
+ exceptiongroup==1.2.1
27
+ fastapi==0.111.0
28
+ fastapi-cli==0.0.4
29
+ ffmpy==0.3.2
30
+ filelock==3.15.4
31
+ fonttools @ file:///Users/runner/miniforge3/conda-bld/fonttools_1717209205562/work
32
+ fpdf @ file:///home/conda/feedstock_root/build_artifacts/fpdf_1606859403225/work
33
+ fsspec==2024.6.1
34
+ gitdb==4.0.11
35
+ GitPython==3.1.43
36
+ gradio==4.37.2
37
+ gradio_client==1.0.2
38
+ h11==0.14.0
39
+ httpcore==1.0.5
40
+ httptools==0.6.1
41
+ httpx==0.27.0
42
+ huggingface-hub==0.23.4
43
+ idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1701026962277/work
44
+ importlib_metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1710971335535/work
45
+ importlib_resources==6.4.0
46
+ Jinja2==3.1.4
47
+ jsonpatch @ file:///home/conda/feedstock_root/build_artifacts/jsonpatch_1695536281965/work
48
+ jsonpointer @ file:///Users/runner/miniforge3/conda-bld/jsonpointer_1695397382064/work
49
+ jsonschema==4.22.0
50
+ jsonschema-specifications==2023.12.1
51
+ kiwisolver @ file:///Users/runner/miniforge3/conda-bld/kiwisolver_1695379982481/work
52
+ libmambapy @ file:///Users/runner/miniforge3/conda-bld/mamba-split_1702310516100/work/libmambapy
53
+ macholib @ file:///home/conda/feedstock_root/build_artifacts/macholib_1695643090386/work
54
+ mamba @ file:///Users/runner/miniforge3/conda-bld/mamba-split_1702310516100/work/mamba
55
+ markdown-it-py==3.0.0
56
+ MarkupSafe==2.1.5
57
+ matplotlib==3.9.0
58
+ mdurl==0.1.2
59
+ menuinst @ file:///Users/runner/miniforge3/conda-bld/menuinst_1702317138933/work
60
+ mpmath==1.3.0
61
+ munkres==1.1.4
62
+ networkx==3.3
63
+ numpy @ file:///Users/runner/miniforge3/conda-bld/numpy_1707225416355/work/dist/numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl#sha256=14c628943f67e9c10d22faa9c1cdcbf69c3192e88f2f597d03b77a252e589567
64
+ opencv-python==4.10.0.84
65
+ opencv-python-headless==4.9.0
66
+ orjson==3.10.6
67
+ packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1696202382185/work
68
+ pandas==2.2.1
69
+ pillow @ file:///Users/runner/miniforge3/conda-bld/pillow_1712154790137/work
70
+ platformdirs @ file:///home/conda/feedstock_root/build_artifacts/platformdirs_1701708255999/work
71
+ pluggy @ file:///home/conda/feedstock_root/build_artifacts/pluggy_1693086607691/work
72
+ psutil==6.0.0
73
+ py-cpuinfo==9.0.0
74
+ pycosat @ file:///Users/runner/miniforge3/conda-bld/pycosat_1696355969704/work
75
+ pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1636257122734/work
76
+ pydantic==2.8.0
77
+ pydantic_core==2.20.0
78
+ pydub==0.25.1
79
+ Pygments==2.18.0
80
+ pyinstaller @ file:///Users/runner/miniforge3/conda-bld/pyinstaller_1713052385294/work
81
+ pyinstaller-hooks-contrib @ file:///home/conda/feedstock_root/build_artifacts/pyinstaller-hooks-contrib_1715408511616/work
82
+ pyparsing @ file:///home/conda/feedstock_root/build_artifacts/pyparsing_1709721012883/work
83
+ PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1661604839144/work
84
+ python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1709299778482/work
85
+ python-dotenv==1.0.1
86
+ python-multipart==0.0.9
87
+ pytz==2024.1
88
+ PyYAML @ file:///Users/runner/miniforge3/conda-bld/pyyaml_1695373498369/work
89
+ referencing==0.35.1
90
+ requests==2.32.3
91
+ rich==13.7.1
92
+ rpds-py==0.18.1
93
+ ruamel.yaml @ file:///Users/runner/miniforge3/conda-bld/ruamel.yaml_1699007390921/work
94
+ ruamel.yaml.clib @ file:///Users/runner/miniforge3/conda-bld/ruamel.yaml.clib_1695996997220/work
95
+ ruff==0.5.0
96
+ scipy @ file:///Users/runner/miniforge3/conda-bld/scipy-split_1719280596793/work/dist/scipy-1.14.0-cp310-cp310-macosx_11_0_arm64.whl#sha256=4a51295ede41379d644725cf3d34511b46af30f887aac9e23b16af0887242ec1
97
+ seaborn==0.13.2
98
+ semantic-version==2.10.0
99
+ shellingham==1.5.4
100
+ six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
101
+ smmap==5.0.1
102
+ sniffio==1.3.1
103
+ starlette==0.37.2
104
+ supervision @ file:///home/conda/feedstock_root/build_artifacts/supervision_1717760466659/work
105
+ sympy==1.12.1
106
+ thop==0.1.1.post2209072238
107
+ tomlkit==0.12.0
108
+ toolz==0.12.1
109
+ torch==2.3.1
110
+ torchvision==0.18.1
111
+ tqdm @ file:///home/conda/feedstock_root/build_artifacts/tqdm_1691671248568/work
112
+ truststore @ file:///home/conda/feedstock_root/build_artifacts/truststore_1694154605758/work
113
+ typer==0.12.3
114
+ typing_extensions==4.12.2
115
+ tzdata==2024.1
116
+ ujson==5.10.0
117
+ ultralytics==8.2.48
118
+ ultralytics-thop==2.0.0
119
+ unicodedata2 @ file:///Users/runner/miniforge3/conda-bld/unicodedata2_1695848003431/work
120
+ urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1699933488691/work
121
+ uvicorn==0.30.1
122
+ uvloop==0.19.0
123
+ watchfiles==0.22.0
124
+ websockets==11.0.3
125
+ zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1695255097490/work
126
+ zstandard==0.22.0
translate_ai.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import assemblyai as aai
3
+ from translate import Translator
4
+ from elevenlabs import VoiceSettings
5
+ from elevenlabs.client import ElevenLabs
6
+ import uuid
7
+ from pathlib import Path
8
+
9
+
10
+ def voice_to_voice():
11
+
12
+ #ceviri
13
+ transcription_response = audio_transcription(audio_file)
14
+
15
+ if transcript.status == aai.TranscriptStatus.error:
16
+ raise gr.Error(transcription_response.error)
17
+ else:
18
+ text = transcription_response.text
19
+
20
+ es_translation, en_translation, ja_translation = text_translation(text)
21
+
22
+ es_audio_path = text_to_speech(es_translation)
23
+ en_audio_path = text_to_speech(en_translation)
24
+ ja_audio_path = text_to_speech(ja_translation)
25
+
26
+ es_path = Path(es_audio_path)
27
+ en_path = Path(en_audio_path)
28
+ ja_path = Path(ja_audio_path)
29
+ return ja_path,en_path,es_path
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ def audio_translation():
38
+
39
+ aai.settings.api_key = "d502d55e78d54bff9c03b19031129069"
40
+
41
+ transcriber = aai.Transcriber()
42
+ transcription = transcriber.transcribe(audio_file)
43
+ return transcription
44
+
45
+
46
+
47
+
48
+
49
+ def text_translation():
50
+
51
+ translator_es(from_lang="tr", to_lang="es")
52
+ es_text = translator_es.translate(text)
53
+
54
+ translator_en(from_lang="tr", to_lang="en")
55
+ en_text = translator_en.translate(text)
56
+
57
+ translator_ja(from_lang="tr", to_lang="ja")
58
+ ja_text = translator_ja.translate(text)
59
+
60
+ return es_text, en_text, ja_text
61
+
62
+ def text_to_speech(text):
63
+
64
+ ELEVENLABS_API_KEY = os.getenv("sk_c65e00fa906e4d07b84d74a83cc2e6661a4a57261ae714ea")
65
+ client = ElevenLabs(
66
+ api_key=ELEVENLABS_API_KEY,
67
+ )
68
+
69
+ # Calling the text_to_speech conversion API with detailed parameters
70
+ response = client.text_to_speech.convert(
71
+ voice_id="pNInz6obpgDQGcFmaJgB", # baha
72
+ optimize_streaming_latency="0",
73
+ output_format="mp3_22050_32",
74
+ text=text,
75
+ model_id="eleven_turbo_v2", # use the turbo model for low latency, for other languages use the `eleven_multilingual_v2`
76
+ voice_settings=VoiceSettings(
77
+ stability=0.0,
78
+ similarity_boost=1.0,
79
+ style=0.0,
80
+ use_speaker_boost=True,
81
+ ),
82
+ )
83
+
84
+ # uncomment the line below to play the audio back
85
+ # play(response)
86
+
87
+ # Generating a unique file name for the output MP3 file
88
+ save_file_path = f"{uuid.uuid4()}.mp3"
89
+
90
+ # Writing the audio to a file
91
+ with open(save_file_path, "wb") as f:
92
+ for chunk in response:
93
+ if chunk:
94
+ f.write(chunk)
95
+
96
+ print(f"{save_file_path}: A new audio file was saved successfully!")
97
+
98
+ # Return the path of the saved audio file
99
+ return save_file_path
100
+
101
+ audio_input = gr.Audio(
102
+ sources=["microphone"],
103
+ type="filepath"
104
+ )
105
+
106
+
107
+ demo = gr.Interface(
108
+ fn=voice_to_voice,
109
+ inputs=audio_input,
110
+ outputs = [gr.Audio(label="Spanish"), gr.Audio(label="Turkish"), gr.Audio(label="Japanese")]
111
+ )
112
+
113
+
114
+ if __name__ == "__main__":
115
+ demo.launch(share=True)
116
+