Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -125,23 +125,23 @@ with gr.Blocks() as demo:
|
|
125 |
output_text = gr.Textbox(label="π Model Prediction", interactive=False)
|
126 |
|
127 |
def extract_features_from_file(file):
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
|
145 |
|
146 |
# Add file upload component
|
147 |
file_input = gr.File(label="π Upload Feature File (for NN)", type="binary", visible=False)
|
|
|
125 |
output_text = gr.Textbox(label="π Model Prediction", interactive=False)
|
126 |
|
127 |
def extract_features_from_file(file):
|
128 |
+
"""Reads a text file and extracts numerical features."""
|
129 |
+
if file is None:
|
130 |
+
return "β Please upload a valid feature file."
|
131 |
|
132 |
+
try:
|
133 |
+
# Read and process file contents
|
134 |
+
content = file.read().decode("utf-8").strip()
|
135 |
+
values = [float(x) for x in content.replace(",", " ").split()]
|
136 |
|
137 |
+
# Check if we have exactly 30 features
|
138 |
+
if len(values) != 30:
|
139 |
+
return "β The file must contain exactly 30 numerical values."
|
140 |
|
141 |
+
return {feature_inputs[i]: values[i] for i in range(30)}
|
142 |
|
143 |
+
except Exception as e:
|
144 |
+
return f"β Error processing file: {e}"
|
145 |
|
146 |
# Add file upload component
|
147 |
file_input = gr.File(label="π Upload Feature File (for NN)", type="binary", visible=False)
|