File size: 961 Bytes
1d9271a
ffc0be2
 
66c9272
8c30f17
a5b5282
ffc0be2
 
 
 
66c9272
 
8c30f17
 
 
 
66c9272
8c30f17
 
 
 
 
66c9272
 
 
8c30f17
 
1d9271a
8c30f17
 
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
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()