Unknownhackerr commited on
Commit
794ad1f
·
verified ·
1 Parent(s): 3d4b3a9

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 pipeline
3
+
4
+ # The pipeline will automatically load the model and tokenizer
5
+ # from the current directory where you've put the files.
6
+ try:
7
+ classifier = pipeline("text-classification", model="./", tokenizer="./")
8
+
9
+ def classify_text(text):
10
+ """
11
+ Classifies a single piece of text and returns a human-readable prediction.
12
+ """
13
+ if not text:
14
+ return "Please enter some text to classify."
15
+
16
+ result = classifier(text)[0]
17
+ label = "Hate Speech" if result['label'] == 'LABEL_1' else "Not Hate Speech"
18
+ score = result['score']
19
+ return f"Prediction: {label}\nConfidence: {score:.4f}"
20
+
21
+ # Create the Gradio interface
22
+ iface = gr.Interface(
23
+ fn=classify_text,
24
+ inputs=gr.Textbox(lines=5, placeholder="Enter a comment in English or Hindi..."),
25
+ outputs=gr.Textbox(label="Result"),
26
+ title="Multilingual Hate Speech Classifier",
27
+ description="A model to classify comments in Hindi and English."
28
+ )
29
+
30
+ iface.launch()
31
+
32
+ except Exception as e:
33
+ # A simple error message box for the user
34
+ gr.Interface(
35
+ lambda x: f"An error occurred: {e}",
36
+ inputs="text",
37
+ outputs="text",
38
+ title="Error Loading Model",
39
+ description="There was an issue loading the model. Please check your files and dependencies."
40
+ ).launch()
41
+