Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import torch
|
4 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
5 |
+
import gradio as gr
|
6 |
+
#task1
|
7 |
+
model_name = "bert-base-multilingual-cased"
|
8 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
9 |
+
model_load=BertForSequenceClassification.from_pretrained("https://huggingface.co/spaces/rima357/FinArgBengali/tree/main/bert-base-multilingual-cased_finetune_FinArgBengali",num_labels=2)
|
10 |
+
def fun_task1(Text):
|
11 |
+
if(Text==""):
|
12 |
+
return "অনুগ্রহ করে প্রথমে টেক্সট লিখুন। (Please enter the text first)"
|
13 |
+
tokenized_text = tokenizer(Text, padding=True, truncation=True, max_length=512, return_tensors="pt")
|
14 |
+
logits = model_load(**tokenized_text).logits
|
15 |
+
output=torch.argmax(logits, axis=1)
|
16 |
+
label=output.tolist()
|
17 |
+
if(label[0]==0):
|
18 |
+
return "ভিত্তি (Premise)"
|
19 |
+
elif(label[0]==1):
|
20 |
+
return "দাবি (Claim)"
|
21 |
+
#task2
|
22 |
+
from sentence_transformers.cross_encoder import CrossEncoder
|
23 |
+
model_load_task2=CrossEncoder("https://huggingface.co/spaces/rima357/FinArgBengali/tree/main/task2-crossEncoder-bert-base-multilingual-cased",num_labels=3)
|
24 |
+
def fun_task2(Text1,Text2):
|
25 |
+
if(Text1=="" or Text2==""):
|
26 |
+
return "অনুগ্রহ করে প্রথমে টেক্সট লিখুন। (Please enter the text first.)"
|
27 |
+
scores = model_load_task2.predict([Text1,Text2])
|
28 |
+
label=np.argmax(scores)
|
29 |
+
if(label==0):
|
30 |
+
return "দুটি পাঠ্যের মধ্যে কোন সনাক্ত করা সম্পর্ক নেই। (There is no relation detected between two texts.)"
|
31 |
+
elif(label==1):
|
32 |
+
return "পাঠ্য 1 থেকে পাঠ্য 2 এর সাথে একটি সমর্থন সম্পর্ক রয়েছে। (There is an “support” relation from text 1 to text 2.)"
|
33 |
+
elif(label==2):
|
34 |
+
return "পাঠ্য 1 থেকে পাঠ্য 2 এর সাথে একটি আক্রমণ সম্পর্ক রয়েছে। (There is an “Attack” relation from text 1 to text 2.)"
|
35 |
+
#gradio app
|
36 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
37 |
+
gr.Markdown("# **The demo toolkit for Financial Argument Analysis in Bengali**")
|
38 |
+
with gr.Tab("Task1-Classify a bengali argumative text into Premise and Claim"):
|
39 |
+
text_input = gr.Textbox(lines=5, placeholder="Enter the text in Bengali...",label="Text")
|
40 |
+
text_button = gr.Button("Classify")
|
41 |
+
text_output = gr.Textbox(label="output")
|
42 |
+
gr.ClearButton([text_input,text_output])
|
43 |
+
example_task1 = gr.Examples(examples=[["আমি বলতে চাচ্ছি, কখনও কখনও এমন হয় না যে আপনি কোনও উজ্জ্বল কৌশল নিয়ে এসেছিলেন, এটি দীর্ঘ সময় ধরে ধারাবাহিকভাবে সত্যিই ভাল কাজ করার মতো।"],
|
44 |
+
["দেখুন, সবার আগে, আমি বলব আমাদের শেয়ারহোল্ডারদের জন্য সুযোগ যখন তারা মাইক্রোসফটের কথা চিন্তা করে তখন আগে কখনও এত ভালো ছিল না।"]],inputs=[text_input])
|
45 |
|
46 |
+
with gr.Tab("Task2-Detection the relation between two bengali argumative texts"):
|
47 |
+
text1_input = gr.Textbox(lines=5, placeholder="Enter the first text in Bengali...",label="Text-1")
|
48 |
+
text2_input = gr.Textbox(lines=5, placeholder="Enter the second text in Bengali...",label="Text-2")
|
49 |
+
task2_button = gr.Button("Detect the relation")
|
50 |
+
task2_output = gr.Textbox(label="output")
|
51 |
+
gr.ClearButton([text1_input,text2_input,task2_output])
|
52 |
+
example_task2 =gr.Examples(examples=[["ইনস্টাগ্রাম আরও দ্রুত বৃদ্ধি পাচ্ছে এবং বৃদ্ধিতে অবদান রাখছে।","আর ইনস্টাগ্রাম যেভাবে এগিয়ে চলেছে তাতে আমরা খুশি।"],
|
53 |
+
["আর এটাই আমাদের দৃষ্টিভঙ্গির মূল কারণ যে আপনারা একটি পার্থক্য দেখতে পাচ্ছেন।","চাহিদা পরিমাপ করা খুব কঠিন, যেমন আপনি জানেন, যখন আপনি আপনার তৈরি করা সবকিছু বিক্রি করছেন।"]],
|
54 |
+
inputs=[text1_input,text2_input])
|
55 |
+
text_button.click(fun_task1, inputs=text_input, outputs=text_output)
|
56 |
+
task2_button.click(fun_task2, inputs=[text1_input,text2_input], outputs=task2_output)
|
57 |
+
|
58 |
+
demo.launch()
|