Ertugrul commited on
Commit
5f1da2d
1 Parent(s): c6edc84

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
2
+ import gradio as gr
3
+
4
+ # def get_model(model_name='Overfit-GM/temp_dist'):
5
+ # id2label = {0: 'INSULT', 1: 'OTHER',
6
+ # 2: 'PROFANITY', 3: 'RACIST', 4: 'SEXIST'}
7
+ # label2id = {v: k for k, v in id2label.items()}
8
+ # tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ # model = AutoModelForSequenceClassification.from_pretrained(model_name,
10
+ # problem_type="single_label_classification",
11
+ # id2label=id2label,
12
+ # label2id=label2id,
13
+ # num_labels=5,
14
+ # output_hidden_states=False,
15
+ # )
16
+ # return model, tokenizer
17
+
18
+
19
+ models = [
20
+ "Overfit-GM/temp_dist",
21
+ "deprem-ml/deprem_bert_128k"
22
+ ]
23
+
24
+ model_box=[
25
+ gr.load(models[0], src='models'),
26
+ gr.load(models[1], src='models'),
27
+ ]
28
+
29
+ def sentiment_analysis(text, model_choice):
30
+
31
+ a_variable = model_box[model_choice]
32
+ output = a_variable(text)
33
+ return output
34
+
35
+ with gr.Blocks() as demo:
36
+ gr.HTML("""<h1 style="font-weight:600;font-size:50;margin-top:4px;margin-bottom:4px;text-align:center;">No Offense Classifier</h1></div>""")
37
+ with gr.Row():
38
+ with gr.Column():
39
+ model_choice = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", interactive=True)
40
+ input_text = gr.Textbox(label="Input", placeholder="senin ben amk")
41
+ the_button = gr.Button(label="Run")
42
+ with gr.Column():
43
+ output_window = gr.Label(num_top_classes=5)
44
+
45
+ the_button.click(sentiment_analysis, inputs=[input_text, model_choice], outputs=[output_window])
46
+ examples = gr.Examples(examples=["bu adamların ülkesine dönmesi lazım", "adam olsan oraya gitmezdin"],
47
+ inputs=[input_text])
48
+
49
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ numpy
4
+ gradio