|
|
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
model_name = "facebook/blenderbot-3B" |
|
|
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
model = AutoModelForCausalLM.from_pretrained(model_name) |
|
|
|
|
|
|
|
|
chat = pipeline("text-generation", model=model, tokenizer=tokenizer) |
|
|
|
|
|
|
|
|
def chatbot_response(message): |
|
|
response = chat(message, max_length=100, do_sample=True, temperature=0.7) |
|
|
return response[0]["generated_text"].replace(message, "").strip() |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=chatbot_response, |
|
|
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."), |
|
|
outputs="text", |
|
|
title="π€ LLM Chatbot with Hugging Face", |
|
|
description="Ask any question and get a response from an open-source LLM!" |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch() |
|
|
|