File size: 771 Bytes
22f8d45
d6d8ac8
22f8d45
d6d8ac8
 
22f8d45
b7e824b
 
 
 
 
 
d6d8ac8
 
 
b7e824b
c2381d0
b7e824b
22f8d45
d6d8ac8
22f8d45
d6d8ac8
b7e824b
d6d8ac8
22f8d45
 
 
a9b9c12
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
import gradio as gr
from transformers import pipeline

# Load your sentiment classification model
pipe = pipeline("text-classification", model="sharmax-vikas/IMDB_Sentiment")

# Label mapping for the model
label_map = {
    "LABEL_0": "Negative",
    "LABEL_1": "Positive"
}

# Define the function used by Gradio
def respond(message, history, *args):
    result = pipe(message)[0]
    label = label_map.get(result["label"], result["label"])  # Map label
    score = round(result["score"]*100, 2)
    return f"Prediction: {label} (Confidence: {score})"

# Create a simple Gradio ChatInterface with your model
demo = gr.ChatInterface(
    fn=respond,
    additional_inputs=[],
    title="IMDB Sentiment Classifier"
)

if __name__ == "__main__":
    demo.launch(share=True)