Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
# Import the necessary libraries
|
4 |
+
import gradio as gr
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# =============================================================================
|
8 |
+
# 1. LOAD YOUR MODEL
|
9 |
+
# =============================================================================
|
10 |
+
# Use a pipeline for easy text classification. This will automatically
|
11 |
+
# load your fine-tuned model and tokenizer from the repository.
|
12 |
+
#
|
13 |
+
# IMPORTANT: Replace "your-username/your-model-repo-name" with your actual model path.
|
14 |
+
# For example: "Tarive/esm2_t12_35M_UR50D-finetuned-pfam-1k"
|
15 |
+
#
|
16 |
+
model_path = "Tarive/esm2_t12_35M_UR50D-finetuned-pfam-1k"
|
17 |
+
classifier = pipeline("text-classification", model=model_path)
|
18 |
+
|
19 |
+
|
20 |
+
# =============================================================================
|
21 |
+
# 2. DEFINE THE PREDICTION FUNCTION
|
22 |
+
# =============================================================================
|
23 |
+
# This function takes a sequence as input and returns a formatted result.
|
24 |
+
def predict_family(sequence):
|
25 |
+
# The pipeline returns a list of dictionaries.
|
26 |
+
# Example: [{'label': 'PF00042', 'score': 0.979}]
|
27 |
+
predictions = classifier(sequence, top_k=5) # Get the top 5 predictions
|
28 |
+
|
29 |
+
# Format the results into a more readable dictionary for display.
|
30 |
+
results = {p['label']: p['score'] for p in predictions}
|
31 |
+
|
32 |
+
return results
|
33 |
+
|
34 |
+
# =============================================================================
|
35 |
+
# 3. CREATE THE GRADIO INTERFACE
|
36 |
+
# =============================================================================
|
37 |
+
# This creates the actual web page interface.
|
38 |
+
iface = gr.Interface(
|
39 |
+
fn=predict_family,
|
40 |
+
inputs=gr.Textbox(
|
41 |
+
lines=10,
|
42 |
+
label="Protein Amino Acid Sequence",
|
43 |
+
placeholder="Paste your protein sequence here..."
|
44 |
+
),
|
45 |
+
outputs=gr.Label(
|
46 |
+
num_top_classes=5,
|
47 |
+
label="Predicted Families"
|
48 |
+
),
|
49 |
+
title="Protein Family Classifier",
|
50 |
+
description="This demo uses a fine-tuned ESM-2 model to predict the protein family from its amino acid sequence. Enter a sequence to see the top 5 predictions and their confidence scores.",
|
51 |
+
examples=[
|
52 |
+
["MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKYR"],
|
53 |
+
["MTEYKLVVVGAGDVGKSALTIQLIQNHFVDEYDPTIEDSYRKQVEVDCQQCMILDILDTAGQEEYSAMRDQYMRTGEGFLCVFAINNTKSFEDIHQYREQIKRVKDSDDVPMVLVGNKCDLAARTVESRQAQDLARSYGIPYIETSAKTRQGVEDAFYTLVREIRQHKLRKLNPPDESGGCMS"]
|
54 |
+
],
|
55 |
+
allow_flagging="never" # Disables the "Flag" button for a cleaner interface
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the interface!
|
59 |
+
iface.launch()
|