Paul-Louis Pröve
commited on
Commit
·
ca98746
1
Parent(s):
94bac12
initial commit
Browse files- .gitignore +1 -0
- app.py +53 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
CSS = """
|
11 |
+
.contain { display: flex; flex-direction: column; }
|
12 |
+
.gradio-container { height: 100vh !important; }
|
13 |
+
#component-0 { height: 100% !important; }
|
14 |
+
#component-1 { height: 100% !important; }
|
15 |
+
#chatbot { flex-grow: 1; overflow: auto;}
|
16 |
+
footer {visibility: hidden}
|
17 |
+
"""
|
18 |
+
|
19 |
+
|
20 |
+
def predict(message, history):
|
21 |
+
history_openai_format = []
|
22 |
+
prompt = """
|
23 |
+
You are ChatGPT, a large language model trained by OpenAI.
|
24 |
+
Carefully read the user's instructions.
|
25 |
+
Respond using Markdown.
|
26 |
+
"""
|
27 |
+
history_openai_format.append({"role": "system", "content": prompt})
|
28 |
+
for human, assistant in history:
|
29 |
+
history_openai_format.append({"role": "user", "content": human})
|
30 |
+
history_openai_format.append({"role": "assistant", "content": assistant})
|
31 |
+
history_openai_format.append({"role": "user", "content": message})
|
32 |
+
|
33 |
+
response = openai.ChatCompletion.create(
|
34 |
+
model="gpt-3.5-turbo",
|
35 |
+
messages=history_openai_format,
|
36 |
+
temperature=0.2,
|
37 |
+
stream=True,
|
38 |
+
)
|
39 |
+
|
40 |
+
partial_message = ""
|
41 |
+
for chunk in response:
|
42 |
+
if len(chunk["choices"][0]["delta"]) != 0:
|
43 |
+
partial_message = partial_message + chunk["choices"][0]["delta"]["content"]
|
44 |
+
yield partial_message
|
45 |
+
|
46 |
+
|
47 |
+
chatbot = gr.Chatbot(elem_id="chatbot")
|
48 |
+
gr.ChatInterface(
|
49 |
+
predict,
|
50 |
+
chatbot=chatbot,
|
51 |
+
title="Tensora GPT-4",
|
52 |
+
css=CSS,
|
53 |
+
).queue().launch(auth=("user", "talktome"))
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
python-dotenv
|