Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
import matplotlib.pyplot as plt
|
4 |
import io
|
|
|
5 |
|
6 |
# Function to parse FCS file and extract data and metadata
|
7 |
def parse_fcs(file):
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Function to plot the data based on selected x and y parameters
|
12 |
def plot_dot(file, x_param, y_param):
|
@@ -32,7 +39,12 @@ def plot_dot(file, x_param, y_param):
|
|
32 |
plt.savefig(buf, format="png")
|
33 |
buf.seek(0)
|
34 |
plt.close()
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
except Exception as e:
|
37 |
return f"Error: {e}"
|
38 |
|
@@ -59,7 +71,7 @@ with gr.Blocks() as app:
|
|
59 |
y_param = gr.Dropdown(label="Y Parameter", choices=[], interactive=True)
|
60 |
|
61 |
plot_btn = gr.Button("Generate Plot")
|
62 |
-
plot_output = gr.Image(type="
|
63 |
|
64 |
# Update parameter dropdowns on file upload
|
65 |
fcs_file.change(get_parameters, inputs=[fcs_file], outputs=[x_param, y_param])
|
@@ -68,4 +80,4 @@ with gr.Blocks() as app:
|
|
68 |
plot_btn.click(plot_dot, inputs=[fcs_file, x_param, y_param], outputs=plot_output)
|
69 |
|
70 |
# Run the app
|
71 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import flowio
|
3 |
import matplotlib.pyplot as plt
|
4 |
import io
|
5 |
+
import pandas as pd
|
6 |
|
7 |
# Function to parse FCS file and extract data and metadata
|
8 |
def parse_fcs(file):
|
9 |
+
# Use flowio to parse the FCS file
|
10 |
+
fcs_data = flowio.FlowData(file.name)
|
11 |
+
|
12 |
+
# Extract channel names and data
|
13 |
+
channel_names = [channel['PnN'] for channel in fcs_data.channels]
|
14 |
+
data = pd.DataFrame(fcs_data.events, columns=channel_names)
|
15 |
+
|
16 |
+
return data, channel_names
|
17 |
|
18 |
# Function to plot the data based on selected x and y parameters
|
19 |
def plot_dot(file, x_param, y_param):
|
|
|
39 |
plt.savefig(buf, format="png")
|
40 |
buf.seek(0)
|
41 |
plt.close()
|
42 |
+
|
43 |
+
# Save the plot as a temporary file for display
|
44 |
+
temp_file = "/tmp/dot_plot.png"
|
45 |
+
with open(temp_file, "wb") as f:
|
46 |
+
f.write(buf.getbuffer())
|
47 |
+
return temp_file
|
48 |
except Exception as e:
|
49 |
return f"Error: {e}"
|
50 |
|
|
|
71 |
y_param = gr.Dropdown(label="Y Parameter", choices=[], interactive=True)
|
72 |
|
73 |
plot_btn = gr.Button("Generate Plot")
|
74 |
+
plot_output = gr.Image(type="filepath", label="Dot Plot")
|
75 |
|
76 |
# Update parameter dropdowns on file upload
|
77 |
fcs_file.change(get_parameters, inputs=[fcs_file], outputs=[x_param, y_param])
|
|
|
80 |
plot_btn.click(plot_dot, inputs=[fcs_file, x_param, y_param], outputs=plot_output)
|
81 |
|
82 |
# Run the app
|
83 |
+
app.launch()
|