|
import gradio as gr |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
model_name = "khaled123/hf" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForCausalLM.from_pretrained(model_name) |
|
|
|
def chat(input_text): |
|
inputs = tokenizer(input_text, return_tensors="pt") |
|
outputs = model.generate(inputs["input_ids"], max_length=150, num_return_sequences=1) |
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
return response |
|
|
|
iface = gr.Interface(fn=chat, |
|
inputs="text", |
|
outputs="text", |
|
title="Chatbot", |
|
description="A chatbot using a model") |
|
|
|
iface.launch() |
|
|
|
|