Lebuga's picture
Upload app.py with huggingface_hub
1b4e7f4 verified
Raw History Blame Contribute Delete
2.64 kB
import gradio as gr
from inference import predict
def predict_ui(sequence):
result = predict(sequence)
if isinstance(result, float):
prob = result
else:
prob = result["probability"]
percent = prob * 100
is_positive = prob > 0.5
label = "🧬 Cleavage Site Likely" if is_positive else "❌ No Cleavage Site"
color = "#22c55e" if is_positive else "#ef4444"
return (
f"{prob:.5f}",
f"{percent:.3f}%",
f"<span style='color:{color}; font-weight:bold; font-size:18px'>{label}</span>",
percent
)
# -----------------------------
# 🎨 Compact + Visible UI
# -----------------------------
css = """
body {
background: linear-gradient(135deg, #0f172a, #020617);
font-family: 'Segoe UI', sans-serif;
}
/* Center container */
.container {
max-width: 650px;
margin: auto;
padding-top: 30px;
}
/* Card */
.card {
background: rgba(255,255,255,0.05);
backdrop-filter: blur(10px);
border-radius: 16px;
padding: 18px;
box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
/* Title fix */
h1 {
color: #ffffff !important;
text-align: center;
margin-bottom: 5px;
}
h3 {
color: #cbd5f5;
text-align: center;
margin-top: 0;
}
/* Reduce input height */
textarea {
min-height: 70px !important;
border-radius: 10px !important;
}
/* Buttons */
button {
border-radius: 10px !important;
padding: 8px 12px !important;
font-weight: bold;
}
/* Reduce spacing */
.gr-box {
padding: 5px !important;
}
"""
with gr.Blocks(css=css) as demo:
with gr.Column(elem_classes="container"):
with gr.Column(elem_classes="card"):
gr.Markdown(
"# 🧬 BiTransformer Cleavage Site Predictor\n"
)
seq_input = gr.Textbox(
label="Protein Sequence",
placeholder="Paste sequence...",
lines=2
)
predict_btn = gr.Button("πŸ” Predict")
with gr.Row():
prob_output = gr.Textbox(label="Probability")
percent_output = gr.Textbox(label="Percentage")
label_output = gr.HTML(label="Result")
confidence_bar = gr.Slider(
minimum=0,
maximum=100,
step=0.1,
label="Confidence",
interactive=False
)
predict_btn.click(
fn=predict_ui,
inputs=seq_input,
outputs=[prob_output, percent_output, label_output, confidence_bar]
)
demo.launch()