sanzanalora commited on
Commit
8632cdd
1 Parent(s): c6eda35

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ # Load the model and tokenizer from Hugging Face Hub
5
+ model_name = "sanzanalora/BanglaBERT_fine-tuned_on_Ben-Sarc" # Update with your model repo name
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Define a function to perform sarcasm detection
10
+ def detect_sarcasm(input_text):
11
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
12
+ outputs = model(**inputs)
13
+ prediction = outputs.logits.argmax(-1).item()
14
+ return "Sarcastic" if prediction == 1 else "Not Sarcastic"
15
+
16
+ # Example Bengali sarcasm sentences
17
+ sarcasm_examples = [
18
+ ["ও হ্যাঁ, তুমি তো অনেক বড় বিজ্ঞানী!"],
19
+ ["অবশ্যই, এই কাজটা খুবই সহজ ছিল।"],
20
+ ["তুমি এত দেরি করো না, সবসময়ই সময়মত আসো!"]
21
+ ]
22
+
23
+ # Gradio interface
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("# Bengali Sarcasm Detection")
26
+ gr.Markdown("**Upload your sarcasm detection model and test it with this Gradio interface.**")
27
+
28
+ with gr.Tab("Sarcasm Detection"):
29
+ gr.Examples(
30
+ sarcasm_examples,
31
+ inputs=gr.Textbox(label="Enter Bengali Text", lines=2),
32
+ outputs=gr.Textbox(label="Prediction")
33
+ )
34
+
35
+ input_text = gr.Textbox(label="Enter your Bengali text for sarcasm detection", lines=2)
36
+ output_text = gr.Textbox(label="Sarcasm Detection Result", lines=2)
37
+
38
+ submit_btn = gr.Button("Detect Sarcasm")
39
+ submit_btn.click(detect_sarcasm, inputs=input_text, outputs=output_text)
40
+
41
+ demo.launch()