Update app.py
Browse files
app.py
CHANGED
|
@@ -31,34 +31,34 @@ class Conversation:
|
|
| 31 |
del self.messages[1:3]
|
| 32 |
return message
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
def on_text_submit(chatbot, txt):
|
| 64 |
prompt = ". ".join([m[0] for m in history if m[1] == "user"])
|
|
|
|
| 31 |
del self.messages[1:3]
|
| 32 |
return message
|
| 33 |
|
| 34 |
+
def add_text(history, text):
|
| 35 |
+
history = history + [(text, None)]
|
| 36 |
+
return history, gr.update(value="", interactive=False)
|
| 37 |
|
| 38 |
+
def add_file(history, file):
|
| 39 |
+
history = history + [((file.name,), None)]
|
| 40 |
+
return history
|
| 41 |
|
| 42 |
+
def bot(history, chatbot):
|
| 43 |
+
prompt = ". ".join([m["content"] for m in history if m["role"] == "user"])
|
| 44 |
+
response = openai.Completion.create(
|
| 45 |
+
engine="davinci",
|
| 46 |
+
prompt=prompt,
|
| 47 |
+
temperature=0.5,
|
| 48 |
+
max_tokens=100,
|
| 49 |
+
top_p=1.0
|
| 50 |
+
)
|
| 51 |
+
message = response["choices"][0]["text"]
|
| 52 |
+
chatbot.add_message(content=message, role="assistant")
|
| 53 |
|
| 54 |
+
def answer(question, history=None):
|
| 55 |
+
if history is None:
|
| 56 |
+
history = []
|
| 57 |
+
history.append(question)
|
| 58 |
+
response = conv.ask(question)
|
| 59 |
+
history.append(response)
|
| 60 |
+
responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
|
| 61 |
+
return responses, history
|
| 62 |
|
| 63 |
def on_text_submit(chatbot, txt):
|
| 64 |
prompt = ". ".join([m[0] for m in history if m[1] == "user"])
|