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