Spaces:
Runtime error
Runtime error
suthanhcong
commited on
Commit
•
bd9be51
1
Parent(s):
924ae75
1st Demo
Browse files- __pycache__/app.cpython-39.pyc +0 -0
- app.py +35 -0
- requirements.txt +3 -0
__pycache__/app.cpython-39.pyc
ADDED
Binary file (1.08 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
from langchain.chat_models import ChatOpenAI
|
4 |
+
from langchain.chains import ConversationChain
|
5 |
+
from langchain.memory import ConversationBufferMemory
|
6 |
+
from langchain.schema import (
|
7 |
+
AIMessage,
|
8 |
+
HumanMessage,
|
9 |
+
SystemMessage
|
10 |
+
)
|
11 |
+
# import random
|
12 |
+
# import time
|
13 |
+
|
14 |
+
llm = ChatOpenAI(temperature=0.0, openai_api_key="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")
|
15 |
+
memory = ConversationBufferMemory()
|
16 |
+
conversation = ConversationChain(
|
17 |
+
llm=llm,
|
18 |
+
memory = memory,
|
19 |
+
# verbose=True
|
20 |
+
)
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
chatbot = gr.Chatbot()
|
24 |
+
msg = gr.Textbox()
|
25 |
+
clear = gr.ClearButton([msg, chatbot])
|
26 |
+
|
27 |
+
def respond(message, chat_history):
|
28 |
+
bot_message = conversation.predict(input=message)
|
29 |
+
chat_history.append((message, bot_message))
|
30 |
+
return "", chat_history
|
31 |
+
|
32 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
langchain
|
3 |
+
gradio
|