File size: 1,314 Bytes
97c8253
09134b2
3d70771
 
 
4a36c79
3d70771
b6c96cc
3d70771
 
 
947c082
3d70771
 
947c082
b6c96cc
947c082
 
 
 
 
 
 
 
3d70771
 
 
 
 
67be4ed
 
3d70771
 
97c8253
 
3d70771
97c8253
3d70771
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
32
33
34
35
36
37
38
39
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):
    # Tokenize the input prompt
    inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
    with torch.no_grad():
        # Get the model output
        outputs = model(**inputs)
    
    # Process the output logits
    logits = outputs.logits
    predicted_class_id = logits.argmax().item()
    
    # Generate a response based on the predicted class
    response = f"Predicted class ID: {predicted_class_id}"
    
    return response

# Create a Gradio interface
iface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(label="Enter your message", placeholder="Type something here..."),
    outputs=gr.Textbox(label="Response"),
    title="Chatbot Interface",
    description="Interact with the fine-tuned chatbot model."
)

# Launch the Gradio app
if __name__ == "__main__":
    iface.launch()