CHATBOT1 / app.py
FridayMaster's picture
Update app.py
09134b2 verified
raw
history blame
1.19 kB
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# Load the model and tokenizer
model_name = 'FridayMaster/fine_tune_embedding' # Replace with your model's repository name
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name) # Use the appropriate class
# Define a function to generate responses
def generate_response(prompt):
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
# Customize the response generation as per your model's output
response = tokenizer.decode(outputs.logits.argmax(dim=-1), skip_special_tokens=True)
return response
# Create a Gradio interface
iface = gr.Interface(
fn=generate_response,
inputs=gr.inputs.Textbox(label="Enter your message", placeholder="Type something here..."),
outputs=gr.outputs.Textbox(label="Response"),
title="Chatbot Interface",
description="Interact with the fine-tuned chatbot model."
)
# Launch the Gradio app
if __name__ == "__main__":
iface.launch()