Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
import os
|
|
|
2 |
import openai
|
3 |
from flask import Flask, request, jsonify, send_file
|
4 |
from transformers import pipeline
|
5 |
-
from openai import OpenAI
|
6 |
from gtts import gTTS
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
-
client = OpenAI()
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
pipe = pipeline(model="seeafricatz/kiaziboraasr")
|
13 |
|
14 |
def transcribe(audio_path):
|
@@ -16,14 +19,12 @@ def transcribe(audio_path):
|
|
16 |
return text
|
17 |
|
18 |
def generate_response(transcribed_text):
|
19 |
-
response =
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
],
|
24 |
-
model="gpt-4"
|
25 |
)
|
26 |
-
return response.choices[0].
|
27 |
|
28 |
def inference(text):
|
29 |
tts = gTTS(text, lang='sw')
|
|
|
1 |
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
import openai
|
4 |
from flask import Flask, request, jsonify, send_file
|
5 |
from transformers import pipeline
|
|
|
6 |
from gtts import gTTS
|
7 |
|
8 |
app = Flask(__name__)
|
|
|
9 |
|
10 |
+
# Load environment variables from .env file
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
14 |
+
os.environ["HF_HOME"] = os.getenv("HF_HOME")
|
15 |
pipe = pipeline(model="seeafricatz/kiaziboraasr")
|
16 |
|
17 |
def transcribe(audio_path):
|
|
|
19 |
return text
|
20 |
|
21 |
def generate_response(transcribed_text):
|
22 |
+
response = openai.Completion.create(
|
23 |
+
engine="davinci",
|
24 |
+
prompt=transcribed_text,
|
25 |
+
max_tokens=50
|
|
|
|
|
26 |
)
|
27 |
+
return response.choices[0].text
|
28 |
|
29 |
def inference(text):
|
30 |
tts = gTTS(text, lang='sw')
|