Spaces:
Sleeping
Sleeping
TintinMeimei
commited on
Commit
•
4dc00e6
1
Parent(s):
296977c
Update main.py
Browse files
main.py
CHANGED
@@ -4,8 +4,18 @@ openai.api_key = "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"
|
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
|
|
|
|
7 |
@app.get("/")
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
8 |
+
|
9 |
@app.get("/")
|
10 |
+
def index() -> FileResponse:
|
11 |
+
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
12 |
+
|
13 |
+
@app.get("/infer_chatgpt")
|
14 |
+
def chatgpt(input):
|
15 |
+
try:
|
16 |
+
prompt = {"role": "user", "content": input}
|
17 |
+
result = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[prompt])
|
18 |
+
output = result.get('choices')[0].get('message').get('content')
|
19 |
+
except Exception as e:
|
20 |
+
output = str(e)
|
21 |
+
return {"output": output}
|