lyimo commited on
Commit
7f898b9
1 Parent(s): 25cf486

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -10
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
- openai.api_key = "sk-proj-zufatzHdsNmcalxgJUG7T3BlbkFJJCw6YnyYqkJhS4xkvrm"
 
 
 
 
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 = client.chat_completions.create(
20
- messages=[
21
- {"role": "system", "content": "All your answers should be in Swahili only..."},
22
- {"role": "user", "content": transcribed_text},
23
- ],
24
- model="gpt-4"
25
  )
26
- return response.choices[0].message.content
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')