Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import AutoTokenizer | |
from peft import AutoPeftModelForCausalLM | |
# Load the model and tokenizer from Hugging Face | |
model_name = "PierreJousselin/lora_model" # Replace with your model's name or path | |
model = AutoPeftModelForCausalLM.from_pretrained( | |
model_name, | |
) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
# Define the chat function | |
def chat_with_model(user_input): | |
# Encode the input | |
inputs = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt") | |
# Generate a response from the model | |
outputs = model.generate(inputs, max_length=1000, pad_token_id=tokenizer.eos_token_id) | |
# Decode the model's output | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# Set up Gradio interface | |
iface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", live=True) | |
# Launch the interface | |
iface.launch() | |