Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
# Load the model and tokenizer from Hugging Face Hub | |
model_name = "sanzanalora/BanglaBERT_fine-tuned_on_Ben-Sarc" # Update with your model repo name | |
model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
# Define a function to perform sarcasm detection | |
def detect_sarcasm(input_text): | |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True) | |
outputs = model(**inputs) | |
prediction = outputs.logits.argmax(-1).item() | |
return "Sarcastic" if prediction == 1 else "Not Sarcastic" | |
# Example Bengali sarcasm sentences | |
sarcasm_examples = [ | |
["ও হ্যাঁ, তুমি তো অনেক বড় বিজ্ঞানী!"], | |
["অবশ্যই, এই কাজটা খুবই সহজ ছিল।"], | |
["তুমি এত দেরি করো না, সবসময়ই সময়মত আসো!"] | |
] | |
# Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("# Bengali Sarcasm Detection") | |
gr.Markdown("**Upload your sarcasm detection model and test it with this Gradio interface.**") | |
with gr.Tab("Sarcasm Detection"): | |
gr.Examples( | |
sarcasm_examples, | |
inputs=gr.Textbox(label="Enter Bengali Text", lines=2), | |
outputs=gr.Textbox(label="Prediction") | |
) | |
input_text = gr.Textbox(label="Enter your Bengali text for sarcasm detection", lines=2) | |
output_text = gr.Textbox(label="Sarcasm Detection Result", lines=2) | |
submit_btn = gr.Button("Detect Sarcasm") | |
submit_btn.click(detect_sarcasm, inputs=input_text, outputs=output_text) | |
demo.launch() | |