andromeda01111 commited on
Commit
f757d50
Β·
verified Β·
1 Parent(s): d89f903

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -124,6 +124,41 @@ with gr.Blocks() as demo:
124
 
125
  output_text = gr.Textbox(label="πŸ” Model Prediction", interactive=False)
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  # Toggle input fields based on model selection
128
  """Toggle visibility of inputs based on model selection."""
129
  def toggle_inputs(choice):
 
124
 
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)
148
+
149
+ # Update UI logic to show file input for NN model
150
+ def toggle_inputs(choice):
151
+ image_visibility = choice == "ViT"
152
+ feature_visibility = choice == "Neural Network"
153
+ file_visibility = choice == "Neural Network"
154
+ return [gr.update(visible=image_visibility)] + [gr.update(visible=feature_visibility)] * len(feature_inputs) + [gr.update(visible=file_visibility)]
155
+
156
+ model_selector.change(toggle_inputs, model_selector, [image_input, *feature_inputs, file_input])
157
+
158
+ # Process uploaded file and populate feature fields
159
+ file_input.change(extract_features_from_file, file_input, feature_inputs)
160
+
161
+
162
  # Toggle input fields based on model selection
163
  """Toggle visibility of inputs based on model selection."""
164
  def toggle_inputs(choice):