Spaces:
Sleeping
Sleeping
u0pdate
Browse files
app.py
CHANGED
@@ -1,7 +1,32 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from langchain.llms import HuggingFacePipeline
|
3 |
+
from transformers import AutoTokenizer
|
4 |
|
5 |
+
# Define the Hugging Face model and tokenizer
|
6 |
+
model_name = "microsoft/DialoGPT-medium"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
+
# Define the LangChain chat agent
|
10 |
+
agent = HuggingFacePipeline(
|
11 |
+
model_name=model_name,
|
12 |
+
task="text2text-generation",
|
13 |
+
tokenizer=tokenizer,
|
14 |
+
)
|
15 |
+
|
16 |
+
# Define the Gradio interface
|
17 |
+
def chatbot_interface(input_text):
|
18 |
+
response = agent(input_text)
|
19 |
+
return response
|
20 |
+
|
21 |
+
# Define the Gradio app
|
22 |
+
gradio_app = gr.Interface(
|
23 |
+
fn=chatbot_interface,
|
24 |
+
inputs=gr.inputs.Textbox(prompt="Say something..."),
|
25 |
+
outputs=gr.outputs.Textbox(),
|
26 |
+
title="LangChain Chatbot",
|
27 |
+
description="A chatbot interface powered by LangChain and Hugging Face.",
|
28 |
+
)
|
29 |
+
|
30 |
+
# Run the Gradio app
|
31 |
+
if __name__ == "__main__":
|
32 |
+
gradio_app.run()
|