DPWXY15 commited on
Commit
a286c29
·
verified ·
1 Parent(s): cbc4afc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, UploadFile, File
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = os.environ["OPENAI_API_KEY"]
6
+
7
+ app = FastAPI()
8
+
9
+ @app.post("/chat")
10
+ async def chat(req: Request):
11
+ data = await req.json()
12
+ messages = data.get("messages", [])
13
+ response = openai.ChatCompletion.create(
14
+ model="gpt-3.5-turbo",
15
+ messages=messages
16
+ )
17
+ return {"reply": response["choices"][0]["message"]["content"]}
18
+
19
+ @app.post("/transcribe")
20
+ async def transcribe(file: UploadFile = File(...)):
21
+ audio_data = await file.read()
22
+ response = openai.Audio.transcribe("whisper-1", audio_data)
23
+ return {"text": response["text"]}