duclo90 commited on
Commit
4b2a1b4
Β·
verified Β·
1 Parent(s): b0bc015

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install dependencies if not already installed
2
+ # !pip install transformers gradio
3
+
4
+ from transformers import pipeline
5
+ import gradio as gr
6
+
7
+ # Load your model and tokenizer from Hugging Face
8
+ model_name = "duclo90/Semeval" # replace with your HF repo
9
+
10
+ classifier = pipeline(
11
+ "text-classification",
12
+ model=model_name,
13
+ tokenizer=model_name
14
+ )
15
+
16
+ # Function to classify text
17
+ def classify_text(text):
18
+ result = classifier(text)
19
+ label = result[0]['label']
20
+ score = round(result[0]['score'], 3)
21
+ return f"Prediction: {label} (Confidence: {score})"
22
+
23
+ # Create Gradio interface
24
+ iface = gr.Interface(
25
+ fn=classify_text,
26
+ inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
27
+ outputs="text",
28
+ title="Human vs Machine Text Classifier",
29
+ description="Enter text and the model will predict if it was written by a human or generated by a machine."
30
+ )
31
+
32
+ # Launch the web app
33
+ iface.launch(share=True) # share=True generates a public link