Nattapong Tapachoom commited on
Commit
57a1eca
·
1 Parent(s): 1ded406

Implement flexible model processing with quality reporting and error handling

Browse files
Files changed (1) hide show
  1. app.py +90 -1
app.py CHANGED
@@ -1137,4 +1137,93 @@ def create_interface():
1137
 
1138
  return demo
1139
 
1140
- # ...existing code...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1137
 
1138
  return demo
1139
 
1140
+ def process_with_flexible_models(input_mode, single_model, suggested_model, multiple_models,
1141
+ model_distribution_mode, task_type, prompt_mode, custom_template,
1142
+ multi_prompts, random_templates, random_variables, file_data,
1143
+ row_preset, custom_rows, max_length, temperature, top_p, batch_size,
1144
+ enable_cleaning, remove_duplicates, min_quality_score,
1145
+ create_splits, export_format):
1146
+ """Process generation with flexible model selection"""
1147
+
1148
+ # Get selected models
1149
+ selected_models = get_selected_models(input_mode, single_model, suggested_model, multiple_models)
1150
+
1151
+ if not selected_models:
1152
+ yield (
1153
+ gr.update(visible=False),
1154
+ gr.update(visible=True, value="❌ กรุณาเลือกโมเดลอย่างน้อยหนึ่งตัว"),
1155
+ {}, "ไม่มีโมเดล", None, None, None, None,
1156
+ "❌ ไม่ได้เลือกโมเดล"
1157
+ )
1158
+ return
1159
+
1160
+ num_samples = get_final_row_count(row_preset, custom_rows)
1161
+
1162
+ try:
1163
+ yield (
1164
+ gr.update(visible=False),
1165
+ gr.update(visible=True, value=f"🔄 กำลังสร้างข้อมูล {num_samples} แถว..."),
1166
+ {}, "กำลังสร้าง...", None, None, None, None,
1167
+ f"🔄 กำลังประมวลผล..."
1168
+ )
1169
+
1170
+ # Simple generation for now
1171
+ model_name = selected_models[0]
1172
+ df, csv_data, json_data, error = generate_dataset_from_task(
1173
+ model_name, task_type, custom_template, file_data,
1174
+ num_samples, max_length, temperature, top_p
1175
+ )
1176
+
1177
+ if error:
1178
+ yield (
1179
+ gr.update(visible=False),
1180
+ gr.update(visible=True, value=f"❌ เกิดข้อผิดพลาด: {error}"),
1181
+ {}, "เกิดข้อผิดพลาด", None, None, None, None,
1182
+ f"❌ {error}"
1183
+ )
1184
+ return
1185
+
1186
+ # Basic quality processing
1187
+ raw_data = df.to_dict('records')
1188
+
1189
+ quality_report = {
1190
+ "total_records": len(raw_data),
1191
+ "models_used": selected_models
1192
+ }
1193
+
1194
+ final_df = pd.DataFrame(raw_data)
1195
+ final_csv = final_df.to_csv(index=False)
1196
+ final_json = json.dumps(raw_data, indent=2, ensure_ascii=False)
1197
+
1198
+ dataset_card = f"# Dataset generated with {model_name}\n\nRecords: {len(raw_data)}"
1199
+
1200
+ success_msg = f"✅ สร้างข้อมูลสำเร็จ! ได้ {len(raw_data)} แถว"
1201
+ quality_summary = f"📊 จำนวนข้อมูล: {len(raw_data)} แถว"
1202
+
1203
+ yield (
1204
+ gr.update(visible=True, value=final_df),
1205
+ gr.update(visible=True, value=success_msg),
1206
+ quality_report,
1207
+ quality_summary,
1208
+ final_csv,
1209
+ final_json,
1210
+ dataset_card,
1211
+ None,
1212
+ "✅ เสร็จสิ้น!"
1213
+ )
1214
+
1215
+ except Exception as e:
1216
+ yield (
1217
+ gr.update(visible=False),
1218
+ gr.update(visible=True, value=f"❌ ข้อผิดพลาด: {str(e)}"),
1219
+ {}, "เกิดข้อผิดพลาด", None, None, None, None,
1220
+ f"❌ {str(e)}"
1221
+ )
1222
+
1223
+ if __name__ == "__main__":
1224
+ demo = create_interface()
1225
+ demo.launch(
1226
+ server_name="0.0.0.0",
1227
+ server_port=7860,
1228
+ share=True
1229
+ )