Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,9 @@ import gradio as gr
|
|
| 2 |
import openai
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
import uvicorn
|
|
|
|
| 5 |
|
| 6 |
-
openai.api_key = "
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
conversation_history = []
|
|
@@ -23,7 +24,7 @@ async def chat(request: Request):
|
|
| 23 |
messages.insert(0, {"role": "system", "content": "You are a story writer. What ever the prompt you always write a story"})
|
| 24 |
|
| 25 |
completion = openai.ChatCompletion.create(
|
| 26 |
-
model="gpt-
|
| 27 |
messages=messages
|
| 28 |
)
|
| 29 |
reply = completion.choices[0].message.content
|
|
@@ -33,12 +34,11 @@ async def chat(request: Request):
|
|
| 33 |
|
| 34 |
return reply
|
| 35 |
|
| 36 |
-
def gradio_chat(message
|
| 37 |
reply = chat(message)
|
| 38 |
-
|
| 39 |
-
return state, state
|
| 40 |
|
| 41 |
-
with gr.ChatInterface(fn=gradio_chat
|
| 42 |
chatbot.launch(server_name="0.0.0.0", server_port=7860)
|
| 43 |
|
| 44 |
# Run the FastAPI app
|
|
|
|
| 2 |
import openai
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
import uvicorn
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
+
openai.api_key = "YOUR_OPENAI_API_KEY"
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
conversation_history = []
|
|
|
|
| 24 |
messages.insert(0, {"role": "system", "content": "You are a story writer. What ever the prompt you always write a story"})
|
| 25 |
|
| 26 |
completion = openai.ChatCompletion.create(
|
| 27 |
+
model="gpt-3.5-turbo",
|
| 28 |
messages=messages
|
| 29 |
)
|
| 30 |
reply = completion.choices[0].message.content
|
|
|
|
| 34 |
|
| 35 |
return reply
|
| 36 |
|
| 37 |
+
def gradio_chat(message):
|
| 38 |
reply = chat(message)
|
| 39 |
+
return reply
|
|
|
|
| 40 |
|
| 41 |
+
with gr.ChatInterface(fn=gradio_chat) as chatbot:
|
| 42 |
chatbot.launch(server_name="0.0.0.0", server_port=7860)
|
| 43 |
|
| 44 |
# Run the FastAPI app
|