umarfarzan commited on
Commit
5c628c4
·
verified ·
1 Parent(s): 6c17bd2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
3
+
4
+ # Hugging Face model path
5
+ MODEL_NAME = "umarfarzan/clipworthy-deberta-model"
6
+
7
+ # Load tokenizer & model
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
10
+
11
+ # Create pipeline
12
+ classifier = pipeline(
13
+ "text-classification",
14
+ model=model,
15
+ tokenizer=tokenizer,
16
+ device=-1 # CPU; set to 0 for GPU
17
+ )
18
+
19
+ # Function to predict and classify as clipworthy/not clipworthy
20
+ def predict_clipworthiness(text):
21
+ if not text.strip():
22
+ return {"error": "No text provided"}
23
+
24
+ # Get raw model prediction
25
+ result = classifier(text, truncation=True, max_length=256)
26
+
27
+ # Extract score (assumes result is a list with a dict containing 'label' and 'score')
28
+ score = result[0]['score']
29
+
30
+ # Return "clipworthy" if score > 0.974, else "not clipworthy"
31
+ label = "clipworthy" if score > 0.971 else "not clipworthy"
32
+
33
+ return {"label": label, "score": score}
34
+
35
+ # Gradio interface
36
+ iface = gr.Interface(
37
+ fn=predict_clipworthiness,
38
+ inputs=gr.Textbox(
39
+ label="Transcript Text",
40
+ placeholder="Paste transcript here..."
41
+ ),
42
+ outputs=gr.JSON(label="Prediction"),
43
+ title="Clipworthy Classifier",
44
+ description="Paste transcript text and get classification results."
45
+ )
46
+
47
+ if __name__ == "__main__":
48
+ iface.launch()