Spaces:
Sleeping
Sleeping
File size: 2,228 Bytes
81093d4 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# -----------------------------
# app.py
# -----------------------------
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F
# -----------------------------
# Load the fine-tuned model
# -----------------------------
MODEL_REPO = "umarfarzan/deberta-best-clipworthiness" # replace with your HF repo
tokenizer = AutoTokenizer.from_pretrained(MODEL_REPO)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_REPO)
model.eval()
# -----------------------------
# Prediction function with colored output
# -----------------------------
def predict_viral(transcript):
"""
Takes a transcript and predicts Viral or Not Viral
"""
inputs = tokenizer(transcript, padding="max_length", truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
probs = F.softmax(logits, dim=-1)
pred_label = torch.argmax(probs, dim=1).item()
pred_prob = probs[0, pred_label].item()
if pred_label == 1:
label_str = f"<span style='color:green;font-weight:bold;'>Viral</span> ({pred_prob*100:.2f}% confidence)"
else:
label_str = f"<span style='color:red;font-weight:bold;'>Not Viral</span> ({pred_prob*100:.2f}% confidence)"
return label_str
# -----------------------------
# Gradio Interface
# -----------------------------
with gr.Blocks(title="Acliptic - Revolutionising The Future Of Clipping") as demo:
gr.Markdown("<h1 style='text-align:center;color:#4B0082;'>Acliptic</h1>")
gr.Markdown("<h3 style='text-align:center;color:#6A5ACD;'>Revolutionising The Future Of Clipping</h3>")
gr.Markdown("---")
with gr.Row():
transcript_input = gr.Textbox(
lines=10,
placeholder="Paste your transcript here...",
label="Transcript"
)
predict_btn = gr.Button("Predict Viral Potential")
result_output = gr.HTML(label="Prediction")
predict_btn.click(fn=predict_viral, inputs=transcript_input, outputs=result_output)
# Launch the interface
demo.launch()
|