Spaces:
Sleeping
Sleeping
download
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 4 |
from uniprot_data import create_dataframe, get_uniprot_data
|
| 5 |
|
|
@@ -12,15 +13,17 @@ def process_uniprot_id(uniprot_id):
|
|
| 12 |
uniprot_id: The UniProt ID.
|
| 13 |
|
| 14 |
Returns:
|
| 15 |
-
|
| 16 |
"""
|
| 17 |
protein_sequence, annotations = get_uniprot_data(uniprot_id)
|
| 18 |
|
| 19 |
if protein_sequence and annotations:
|
| 20 |
df = create_dataframe(protein_sequence, annotations)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
# Gradio Interface
|
|
@@ -58,8 +61,13 @@ with gr.Blocks() as demo:
|
|
| 58 |
)
|
| 59 |
|
| 60 |
output_df = gr.Dataframe(interactive=False)
|
|
|
|
| 61 |
|
| 62 |
-
submit_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
demo.launch()
|
|
|
|
| 1 |
+
import io
|
| 2 |
import gradio as gr
|
| 3 |
+
import tempfile
|
| 4 |
|
| 5 |
from uniprot_data import create_dataframe, get_uniprot_data
|
| 6 |
|
|
|
|
| 13 |
uniprot_id: The UniProt ID.
|
| 14 |
|
| 15 |
Returns:
|
| 16 |
+
Tuple of (DataFrame, downloadable file) or error message
|
| 17 |
"""
|
| 18 |
protein_sequence, annotations = get_uniprot_data(uniprot_id)
|
| 19 |
|
| 20 |
if protein_sequence and annotations:
|
| 21 |
df = create_dataframe(protein_sequence, annotations)
|
| 22 |
+
# Create Excel file
|
| 23 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
|
| 24 |
+
df.to_excel(temp_file.name, index=False)
|
| 25 |
+
return df, temp_file.name
|
| 26 |
+
return "Could not retrieve or process data for the given Uniprot ID", None
|
| 27 |
|
| 28 |
|
| 29 |
# Gradio Interface
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
output_df = gr.Dataframe(interactive=False)
|
| 64 |
+
download_btn = gr.DownloadButton(label="Download Excel")
|
| 65 |
|
| 66 |
+
outputs = submit_btn.click(
|
| 67 |
+
fn=process_uniprot_id,
|
| 68 |
+
inputs=input_text,
|
| 69 |
+
outputs=[output_df, download_btn]
|
| 70 |
+
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
demo.launch()
|