File size: 1,444 Bytes
5c628c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

# Hugging Face model path
MODEL_NAME = "umarfarzan/clipworthy-deberta-model"

# Load tokenizer & model
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)

# Create pipeline
classifier = pipeline(
    "text-classification",
    model=model,
    tokenizer=tokenizer,
    device=-1  # CPU; set to 0 for GPU
)

# Function to predict and classify as clipworthy/not clipworthy
def predict_clipworthiness(text):
    if not text.strip():
        return {"error": "No text provided"}
    
    # Get raw model prediction
    result = classifier(text, truncation=True, max_length=256)
    
    # Extract score (assumes result is a list with a dict containing 'label' and 'score')
    score = result[0]['score']
    
    # Return "clipworthy" if score > 0.974, else "not clipworthy"
    label = "clipworthy" if score > 0.971 else "not clipworthy"
    
    return {"label": label, "score": score}

# Gradio interface
iface = gr.Interface(
    fn=predict_clipworthiness,
    inputs=gr.Textbox(
        label="Transcript Text",
        placeholder="Paste transcript here..."
    ),
    outputs=gr.JSON(label="Prediction"),
    title="Clipworthy Classifier",
    description="Paste transcript text and get classification results."
)

if __name__ == "__main__":
    iface.launch()