gokceuludogan commited on
Commit
8b6ab08
·
verified ·
1 Parent(s): 2affc09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -19,17 +19,21 @@ DESCRIPTION = """"
19
  CITATION = """"
20
  """
21
 
22
- def binary_classification(input):
23
- model = pipeline(model='gokceuludogan/berturk_tr_hate_print_w0.1', token=token)
24
  return model(input)[0]
25
 
26
- def category_classification(input):
27
- model = pipeline(model='gokceuludogan/berturk_tr_hateprint_cat_w0.1_b128', token=token)
28
  return model(input)[0]
29
 
30
  def target_detection(input):
31
- model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_target', token=token)
32
- return model(input)[0]
 
 
 
 
33
 
34
  with gr.Blocks(theme="abidlabs/Lime") as demo:
35
 
@@ -44,25 +48,26 @@ with gr.Blocks(theme="abidlabs/Lime") as demo:
44
  with gr.Column():
45
  with gr.Row():
46
  with gr.Column():
47
- # sentiment_choice = gr.Radio(choices = ["turna_", "berturk"], label ="Model", value="turna_")
48
  sentiment_input = gr.Textbox(label="Input")
49
 
50
  sentiment_submit = gr.Button()
51
  sentiment_output = gr.Textbox(label="Output")
52
- sentiment_submit.click(binary_classification, inputs=[sentiment_input], outputs=sentiment_output)
53
- sentiment_examples = gr.Examples(examples = binary_example, inputs = [sentiment_input], outputs=sentiment_output, fn=binary_classification)
54
 
55
  with gr.Tab("Hate Speech Categorization"):
56
  gr.Markdown("Enter a hateful text to categorize or try the example.")
57
  with gr.Column():
58
  with gr.Row():
59
  with gr.Column():
 
60
  text_input = gr.Textbox(label="Input")
61
 
62
  text_submit = gr.Button()
63
  text_output = gr.Textbox(label="Output")
64
- text_submit.click(category_classification, inputs=[text_input], outputs=text_output)
65
- text_examples = gr.Examples(examples = category_example,inputs=[text_input], outputs=text_output, fn=category_classification)
66
 
67
 
68
  with gr.Tab("Target Detection"):
@@ -74,8 +79,20 @@ with gr.Blocks(theme="abidlabs/Lime") as demo:
74
  nli_submit = gr.Button()
75
  nli_output = gr.Textbox(label="Output")
76
  nli_submit.click(target_detection, inputs=[nli_first_input], outputs=nli_output)
77
- nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=target_example)
 
78
 
 
 
 
 
 
 
 
 
 
 
 
79
  gr.Markdown(CITATION)
80
 
81
  demo.launch()
 
19
  CITATION = """"
20
  """
21
 
22
+ def binary_classification(input, choice):
23
+ model = pipeline(model=f'gokceuludogan/{choice}')
24
  return model(input)[0]
25
 
26
+ def category_classification(input, choice):
27
+ model = pipeline(model=f'gokceuludogan/{choice}')
28
  return model(input)[0]
29
 
30
  def target_detection(input):
31
+ model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_target')
32
+ return model(input)[0]['generated_text']
33
+
34
+ def multi_detection(input):
35
+ model = pipeline(model='gokceuludogan/turna_generation_tr_hateprint_multi')
36
+ return model(input)[0]['generated_text']
37
 
38
  with gr.Blocks(theme="abidlabs/Lime") as demo:
39
 
 
48
  with gr.Column():
49
  with gr.Row():
50
  with gr.Column():
51
+ sentiment_choice = gr.Radio(choices = ["turna_tr_hateprint", "turna_tr_hateprint_5e6_w0.1_", "berturk_tr_hateprint_w0.1", "berturk_tr_hateprint_w0.1_b128"], label ="Model", value="turna_tr_hateprint")
52
  sentiment_input = gr.Textbox(label="Input")
53
 
54
  sentiment_submit = gr.Button()
55
  sentiment_output = gr.Textbox(label="Output")
56
+ sentiment_submit.click(binary_classification, inputs=[sentiment_input, sentiment_choice], outputs=sentiment_output)
57
+ sentiment_examples = gr.Examples(examples = binary_example, inputs = [sentiment_input, sentiment_choice], outputs=sentiment_output, fn=binary_classification)
58
 
59
  with gr.Tab("Hate Speech Categorization"):
60
  gr.Markdown("Enter a hateful text to categorize or try the example.")
61
  with gr.Column():
62
  with gr.Row():
63
  with gr.Column():
64
+ text_choice = gr.Radio(choices= ["berturk_tr_hateprint_cat_w0.1_b128", "berturk_tr_hateprint_cat_w0.1"])
65
  text_input = gr.Textbox(label="Input")
66
 
67
  text_submit = gr.Button()
68
  text_output = gr.Textbox(label="Output")
69
+ text_submit.click(category_classification, inputs=[text_input, text_choice], outputs=text_output)
70
+ text_examples = gr.Examples(examples = category_example,inputs=[text_input, text_choice], outputs=text_output, fn=category_classification)
71
 
72
 
73
  with gr.Tab("Target Detection"):
 
79
  nli_submit = gr.Button()
80
  nli_output = gr.Textbox(label="Output")
81
  nli_submit.click(target_detection, inputs=[nli_first_input], outputs=nli_output)
82
+ nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=target_detection)
83
+
84
 
85
+ with gr.Tab("Multi Detection"):
86
+ gr.Markdown("Enter text to detect hate, category, and targets ")
87
+ with gr.Column():
88
+ with gr.Row():
89
+ with gr.Column():
90
+ nli_first_input = gr.Textbox(label="Input")
91
+ nli_submit = gr.Button()
92
+ nli_output = gr.Textbox(label="Output")
93
+ nli_submit.click(multi_detection, inputs=[nli_first_input], outputs=nli_output)
94
+ nli_examples = gr.Examples(examples = target_example, inputs = [nli_first_input], outputs=nli_output, fn=multi_detection)
95
+
96
  gr.Markdown(CITATION)
97
 
98
  demo.launch()