Spaces:
Runtime error
Runtime error
Reverse version
Browse files- .gitignore +1 -0
- app.py +23 -25
- requirements.txt +1 -1
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
rt/
|
app.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
import threading as th
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
os.environ['OPENAI_API_KEY']="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"
|
| 7 |
-
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
def translateoutput(text,language):
|
| 11 |
-
completion =
|
| 12 |
model="gpt-3.5-turbo",
|
| 13 |
messages=[
|
| 14 |
{"role": "system", "content": f"You will be provided with a sentence in English, and your task is to translate it into {language}."},
|
| 15 |
{"role": "user", "content":text}
|
| 16 |
]
|
| 17 |
)
|
| 18 |
-
return completion.choices[0]
|
| 19 |
|
| 20 |
|
| 21 |
# Initialize a global variable to hold previous output
|
|
@@ -83,29 +81,29 @@ language_info={
|
|
| 83 |
|
| 84 |
def translate(audio_file,lan):
|
| 85 |
message=""
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
th.current_thread().return_value=message
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
def transcription(audio_file,input_lang):
|
| 101 |
global language_info
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
|
| 110 |
|
| 111 |
|
|
@@ -136,7 +134,7 @@ def gpt_api(text):
|
|
| 136 |
return ""
|
| 137 |
if len(text)>2000:
|
| 138 |
text=text[-2000:]
|
| 139 |
-
completion =
|
| 140 |
model="gpt-3.5-turbo",
|
| 141 |
messages=[
|
| 142 |
{"role": "system", "content": "your task is to make a concise summery of text in the same language used in given text"},
|
|
@@ -144,7 +142,7 @@ def gpt_api(text):
|
|
| 144 |
]
|
| 145 |
)
|
| 146 |
|
| 147 |
-
message=completion.choices[0]
|
| 148 |
th.current_thread().return_value=message
|
| 149 |
|
| 150 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
import threading as th
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
openai.api_key = "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"
|
| 7 |
|
| 8 |
def translateoutput(text,language):
|
| 9 |
+
completion = openai.ChatCompletion.create(
|
| 10 |
model="gpt-3.5-turbo",
|
| 11 |
messages=[
|
| 12 |
{"role": "system", "content": f"You will be provided with a sentence in English, and your task is to translate it into {language}."},
|
| 13 |
{"role": "user", "content":text}
|
| 14 |
]
|
| 15 |
)
|
| 16 |
+
return completion.choices[0]['message']['content']
|
| 17 |
|
| 18 |
|
| 19 |
# Initialize a global variable to hold previous output
|
|
|
|
| 81 |
|
| 82 |
def translate(audio_file,lan):
|
| 83 |
message=""
|
| 84 |
+
with open(audio_file, 'rb') as f:
|
| 85 |
+
result = openai.Audio.translate("whisper-1", f)
|
| 86 |
+
text=result.text
|
| 87 |
+
# translation_text += text
|
| 88 |
+
if lan=="English" or lan=="Other" or text=="":
|
| 89 |
+
message=text
|
| 90 |
+
else:
|
| 91 |
+
|
| 92 |
+
text=translateoutput(text,lan)
|
| 93 |
+
message=text
|
| 94 |
th.current_thread().return_value=message
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
def transcription(audio_file,input_lang):
|
| 99 |
global language_info
|
| 100 |
+
with open(audio_file, 'rb') as f:
|
| 101 |
+
if input_lang=="Other":
|
| 102 |
+
result = openai.Audio.transcribe("whisper-1", f)
|
| 103 |
+
th.current_thread().return_value=result.text
|
| 104 |
+
else:
|
| 105 |
+
result = openai.Audio.transcribe("whisper-1", f,language=language_info[input_lang])
|
| 106 |
+
th.current_thread().return_value=result.text
|
| 107 |
|
| 108 |
|
| 109 |
|
|
|
|
| 134 |
return ""
|
| 135 |
if len(text)>2000:
|
| 136 |
text=text[-2000:]
|
| 137 |
+
completion = openai.ChatCompletion.create(
|
| 138 |
model="gpt-3.5-turbo",
|
| 139 |
messages=[
|
| 140 |
{"role": "system", "content": "your task is to make a concise summery of text in the same language used in given text"},
|
|
|
|
| 142 |
]
|
| 143 |
)
|
| 144 |
|
| 145 |
+
message=completion.choices[0]['message']['content']
|
| 146 |
th.current_thread().return_value=message
|
| 147 |
|
| 148 |
|
requirements.txt
CHANGED
|
@@ -37,7 +37,7 @@ matplotlib==3.8.1
|
|
| 37 |
mdurl==0.1.2
|
| 38 |
multidict==6.0.4
|
| 39 |
numpy==1.26.1
|
| 40 |
-
openai==
|
| 41 |
orjson==3.9.10
|
| 42 |
packaging==23.2
|
| 43 |
pandas==2.1.2
|
|
|
|
| 37 |
mdurl==0.1.2
|
| 38 |
multidict==6.0.4
|
| 39 |
numpy==1.26.1
|
| 40 |
+
openai==0.28.1
|
| 41 |
orjson==3.9.10
|
| 42 |
packaging==23.2
|
| 43 |
pandas==2.1.2
|