Skip to content

Commit

Permalink
feat: solve some problem
Browse files Browse the repository at this point in the history
  • Loading branch information
msadeqsirjani committed Jan 15, 2024
1 parent 0c00705 commit 355adc8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .idea/BarkTalk.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 17 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

CORS(app=app)


@app.route("/download/<file_name>")
def download(file_name: str):
file_path = os.path.join(MEDIA_DIR, file_name)
Expand All @@ -28,15 +29,13 @@ def download(file_name: str):

return_data.seek(0)

# os.remove(file_path)
os.remove(file_path)

return send_file(path_or_file=return_data,
download_name=file_name,
mimetype='audio/wav',
as_attachment=True)

# return send_file(path_or_file=file_path, as_attachment=True)


@app.route("/supported_language")
def supported_language():
Expand Down Expand Up @@ -103,15 +102,15 @@ def ask(language: str):
@app.route("/ask/web/<language>", methods=["POST"])
def ask_web(language: str):
data = request.get_json()

file_name = data['file_name']
file_content = data['file_content']

if file_name == "":
return jsonify({"data": None,
"message": "No selected file is available",
"status": "error"}), 400
"status": "error"}), 400

if file_name and file_content and allowed_file(file_name=file_name):
secure_file_name = secure_filename(file_name)
secure_file_extension = get_file_extension(file_name=secure_file_name)
Expand All @@ -137,30 +136,27 @@ def ask_web(language: str):
answer_text = engine.command(prompt=prompt)

exact_answer_voice_name = text_to_speech.convert(text=answer_text,
language=language)
language=language)

data = {
"prompt": prompt,
"prompt_language": language,
"answer": {
"text": answer_text,
"file_name": exact_answer_voice_name,
"answer_language": language,
"voice_path": url_for("download", file_name=exact_answer_voice_name, _external=True, _scheme="http")
}
}
"prompt": prompt,
"prompt_language": language,
"answer": {
"text": answer_text,
"file_name": exact_answer_voice_name,
"answer_language": language,
"voice_path": url_for("download", file_name=exact_answer_voice_name, _external=True, _scheme="http")
}
}

return jsonify({"data": data,
"message": None,
"status": "success"}), 200

# return jsonify({"data": None,
# "message": "DONE",
# "status": "success"}), 200
"status": "success"}), 200
else:
return jsonify({"data": None,
"message": "File type not allowed. Only mp3 and wav files are acceptable",
"status": "error"}), 400


if __name__ == '__main__':
app.run()
23 changes: 13 additions & 10 deletions brain_engine/gpt_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from config import OPENAI_KEY

pre_content = """Note that if you cannot answer the question which is about something you do not know such as time-sensitive information(e.g. today's weather/stock, .etc), you can only reply \"IDK\" in your response without other characters. Do not say something like As an AI language model..., I'm sorry... and etc."""
pre_content = """Configure Chat GPT to operate as a voice assistant capable of addressing a broad array of inquiries. Upon encountering queries beyond its expertise or those it cannot fulfil, it should politely convey its limitation with a phrase such as, "I apologize, but I don't have information on this topic."""


class GptEngine:
Expand All @@ -14,16 +14,19 @@ def __init__(self):
]

def command(self, prompt: str) -> str:
prompt += "\n"
try:
prompt += "\n"

self.messages.append({"role": "user", "content": prompt})
self.messages.append({"role": "user", "content": prompt})

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=self.messages
)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=self.messages
)

content = response.choices[0]['message']['content']
self.messages.append({"role": "assistant", "content": content})
content = response.choices[0]['message']['content']
self.messages.append({"role": "assistant", "content": content})

return content.replace("\n", "")
return content.replace("\n", "")
except Exception as err:
return print(err)
8 changes: 8 additions & 0 deletions liara.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"disks": [
{
"name": "barktalk-api-disk",
"mountTo": "media"
}
]
}

0 comments on commit 355adc8

Please sign in to comment.