Spaces:
Sleeping
Sleeping
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() | |