Spaces:
Sleeping
Sleeping
import json | |
import gradio as gr | |
with open("default_inputs.json", "r") as default_inputs_file: | |
DEFAULT_INPUTS = json.load(default_inputs_file) | |
def set_default_inputs(): | |
return (DEFAULT_INPUTS["dna_sequence"], | |
DEFAULT_INPUTS["latitude"], | |
DEFAULT_INPUTS["longitude"]) | |
def predict_genus(): | |
dna_df = pd.read_csv(dna_file.name) | |
dnaenv_df = pd.read_csv(dnaenv_file.name) | |
results = [] | |
# envdna_genuses = predict_genus_dna_env(dnaenv_df) | |
# dna_genuses = predict_genus_dna(dna_df) | |
# images = [get_genus_image(genus) for genus in top_5_genuses] | |
genuses = xgboost_infer.infer() | |
results.append({ | |
"sequence": dna_df['nucraw'], | |
# "predictions": pd.concat([dna_genuses, envdna_genuses], axis=0) | |
'predictions': genuses | |
}) | |
return results | |
with gr.Blocks() as demo: | |
# Header section | |
gr.Markdown("# DNA Identifier Tool") | |
gr.Markdown("Welcome to Lofi Amazon Beats' DNA Identifier Tool") | |
with gr.Tab("Genus Prediction"): | |
gr.Markdown("Input a DNA sequence and the coordinates at which its sample was taken to predict the genus of the DNA. Click 'I'm feeling lucky' to see our predictio for a random sequence.") | |
# Collect inputs for app (DNA and location) | |
with gr.Row(): | |
inp_dna = gr.Textbox(label="DNA", placeholder="e.g. AACAATGTA... (will be automatically truncated to 660 characters)") | |
with gr.Row(): | |
inp_lat = gr.Textbox(label="Latitude", placeholder="e.g. -3.009083") | |
inp_lng = gr.Textbox(label="Longitude", placeholder="e.g. -58.68281") | |
with gr.Row(): | |
btn_run = gr.Button("Run") | |
btn_defaults = gr.Button("I'm feeling lucky") | |
btn_defaults.click(fn=set_default_inputs, outputs=[inp_dna, inp_lat, inp_lng]) | |
with gr.Row(): | |
gr.Markdown('Make plot or table for Top 5 species') | |
with gr.Column(): | |
genus_out = gr.Dataframe(headers=["DNA", "Coord", "DNA Only Pred Genus", "DNA Only Prob", "DNA & Env Pred Genus", "DNA & Env Prob"]) | |
btn_run.click(predict_genus, inputs=[inp_dna, inp_lat, inp_lng], outputs=genus_out) | |
with gr.Tab('DNA Embedding Space Similarity Visualizer'): | |
gr.Markdown("If the highest genus probability is very low for your DNA sequence, we can still examine the DNA embedding of the sequence in relation to known samples or clues.") | |
demo.launch() | |