Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,29 +3,50 @@ import gradio as gr
|
|
3 |
# from llama_index import GPTVectorStoreIndex
|
4 |
# from query_data import get_chain
|
5 |
from langchain.chat_models import ChatOpenAI
|
6 |
-
from langchain import LLMChain
|
7 |
-
from langchain.chat_models import ChatOpenAI
|
8 |
-
from langchain.prompts.chat import (
|
9 |
-
ChatPromptTemplate,
|
10 |
-
SystemMessagePromptTemplate,
|
11 |
-
HumanMessagePromptTemplate,
|
12 |
-
)
|
13 |
-
from langchain.agents import initialize_agent, AgentType
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
agent = initialize_agent(llm, AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION)
|
18 |
|
19 |
-
# define function to
|
20 |
-
def
|
21 |
-
response =
|
22 |
return response
|
23 |
|
24 |
-
# create Gradio interface
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
# launch interface
|
28 |
-
iface.launch()
|
29 |
|
30 |
"""chat = ChatOpenAI(temperature=0)
|
31 |
|
|
|
3 |
# from llama_index import GPTVectorStoreIndex
|
4 |
# from query_data import get_chain
|
5 |
from langchain.chat_models import ChatOpenAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# create the OpenAI chatbot
|
8 |
+
chatbot = ChatOpenAI()
|
|
|
9 |
|
10 |
+
# define the function to generate the chatbot response
|
11 |
+
def generate_response(text):
|
12 |
+
response = chatbot.generate_response(text)
|
13 |
return response
|
14 |
|
15 |
+
# create the Gradio interface
|
16 |
+
interface = gr.Interface(
|
17 |
+
fn=generate_response,
|
18 |
+
inputs=gr.inputs.Textbox(label="Input Text"),
|
19 |
+
outputs=gr.outputs.Textbox(label="Output Text")
|
20 |
+
)
|
21 |
+
|
22 |
+
# launch the interface
|
23 |
+
interface.launch()
|
24 |
+
|
25 |
+
#from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
|
26 |
+
#from langchain.memory import ConversationBufferWindowMemory
|
27 |
+
|
28 |
+
#template =
|
29 |
+
"""You are a brilliant and empathic counselor. You encourage human to share feelings.
|
30 |
+
You provide resources when appropriate or if asked.
|
31 |
+
{history}
|
32 |
+
Human: {human_input}
|
33 |
+
Assistant:"""
|
34 |
+
|
35 |
+
"""prompt = PromptTemplate(input_variables=["history", "human_input"], template=template)
|
36 |
+
|
37 |
+
chatgpt_chain = LLMChain(
|
38 |
+
llm=OpenAI(temperature=0.8),
|
39 |
+
prompt=prompt,
|
40 |
+
verbose=False,
|
41 |
+
memory=ConversationBufferWindowMemory(k=2),
|
42 |
+
)
|
43 |
+
|
44 |
+
output = chatgpt_chain.predict(
|
45 |
+
human_input=
|
46 |
+
|
47 |
+
iface = gr.Interface(fn=get_response, inputs="text", outputs="text")"""
|
48 |
+
|
49 |
|
|
|
|
|
50 |
|
51 |
"""chat = ChatOpenAI(temperature=0)
|
52 |
|