Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,20 +80,9 @@ class SyntheticDataGenerator:
|
|
| 80 |
except Exception as e:
|
| 81 |
return None, f"Synthetic data generation failed with error: {str(e)}"
|
| 82 |
|
| 83 |
-
# ---- Report helpers ----
|
| 84 |
-
def get_quality_report_text(self) -> str:
|
| 85 |
-
"""Return a concise status about the report."""
|
| 86 |
-
if not self.generator:
|
| 87 |
-
return "No trained generator available. Please train a model first."
|
| 88 |
-
try:
|
| 89 |
-
_ = self.generator.reports(display=False) # builds report internally
|
| 90 |
-
return "Quality report generated. Use the button to download."
|
| 91 |
-
except Exception as e:
|
| 92 |
-
return f"Failed to generate quality report: {str(e)}"
|
| 93 |
-
|
| 94 |
def get_quality_report_file(self) -> Optional[str]:
|
| 95 |
"""
|
| 96 |
-
Generate/export the report and return a file path for download.
|
| 97 |
Tries to find an existing ZIP; otherwise saves a TXT fallback.
|
| 98 |
"""
|
| 99 |
if not self.generator:
|
|
@@ -194,19 +183,6 @@ def generate_data(size: int) -> Tuple[Optional[pd.DataFrame], str]:
|
|
| 194 |
return synthetic_df, f"{status}: {message}"
|
| 195 |
|
| 196 |
|
| 197 |
-
def get_quality_report_and_file():
|
| 198 |
-
"""
|
| 199 |
-
Return (status_text, download_component_update)
|
| 200 |
-
The second value updates the DownloadButton with the file path and visibility.
|
| 201 |
-
"""
|
| 202 |
-
status = generator.get_quality_report_text()
|
| 203 |
-
path = generator.get_quality_report_file()
|
| 204 |
-
if path:
|
| 205 |
-
return status, gr.update(value=path, visible=True)
|
| 206 |
-
else:
|
| 207 |
-
return status, gr.update(visible=False)
|
| 208 |
-
|
| 209 |
-
|
| 210 |
def create_comparison_plot(original_df: pd.DataFrame, synthetic_df: pd.DataFrame) -> Optional[go.Figure]:
|
| 211 |
if original_df is None or synthetic_df is None:
|
| 212 |
return None
|
|
@@ -311,11 +287,9 @@ def create_interface():
|
|
| 311 |
train_btn = gr.Button("Train Model", variant="primary")
|
| 312 |
with gr.Column():
|
| 313 |
train_status = gr.Textbox(label="Training Status", interactive=False)
|
| 314 |
-
quality_report = gr.Textbox(label="Quality Report", lines=8, interactive=False)
|
| 315 |
|
| 316 |
with gr.Row():
|
| 317 |
-
get_report_btn = gr.
|
| 318 |
-
report_download_btn = gr.DownloadButton("Download Quality Report", visible=False)
|
| 319 |
|
| 320 |
with gr.Tab("Generate Data"):
|
| 321 |
gr.Markdown("### Generate synthetic data from your trained model")
|
|
@@ -331,31 +305,6 @@ def create_interface():
|
|
| 331 |
download_btn = gr.DownloadButton("Download CSV", variant="secondary")
|
| 332 |
comparison_plot = gr.Plot(label="Data Comparison")
|
| 333 |
|
| 334 |
-
# README footer
|
| 335 |
-
gr.Markdown(
|
| 336 |
-
"""
|
| 337 |
-
**Modes of operation:**
|
| 338 |
-
- **LOCAL mode** trains and generates synthetic data on your own compute resources.
|
| 339 |
-
- **CLIENT mode** connects to a remote MOSTLY AI platform for training and generation.
|
| 340 |
-
- Generators trained locally can be imported to the platform for sharing and collaboration.
|
| 341 |
-
|
| 342 |
-
**Key resources managed by the SDK:**
|
| 343 |
-
- **Generators**: Train on your tabular or language data assets.
|
| 344 |
-
- **Synthetic datasets**: Generate any number of synthetic samples as needed.
|
| 345 |
-
- **Connectors**: Connect to organizational data sources for reading and writing data.
|
| 346 |
-
|
| 347 |
-
**Common intents and API primitives:**
|
| 348 |
-
- Train a generator: `g = mostly.train(config)`
|
| 349 |
-
- Generate records: `sd = mostly.generate(g, config)`
|
| 350 |
-
- Probe generator: `df = mostly.probe(g, config)`
|
| 351 |
-
- Connect to data source: `c = mostly.connect(config)`
|
| 352 |
-
|
| 353 |
-
The open source Synthetic Data SDK by MOSTLY AI powers the MOSTLY AI Platform and MOSTLY AI Assistant.
|
| 354 |
-
|
| 355 |
-
Sign up for free and try the [MOSTLY AI Platform](https://app.mostly.ai/) today!
|
| 356 |
-
"""
|
| 357 |
-
)
|
| 358 |
-
|
| 359 |
# ---- Event handlers ----
|
| 360 |
init_btn.click(initialize_sdk, outputs=[init_status])
|
| 361 |
|
|
@@ -365,11 +314,8 @@ def create_interface():
|
|
| 365 |
outputs=[train_status],
|
| 366 |
)
|
| 367 |
|
| 368 |
-
#
|
| 369 |
-
get_report_btn.click(
|
| 370 |
-
get_quality_report_and_file,
|
| 371 |
-
outputs=[quality_report, report_download_btn],
|
| 372 |
-
)
|
| 373 |
|
| 374 |
# Generate data
|
| 375 |
generate_btn.click(generate_data, inputs=[gen_size], outputs=[synthetic_data, gen_status])
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
return None, f"Synthetic data generation failed with error: {str(e)}"
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def get_quality_report_file(self) -> Optional[str]:
|
| 84 |
"""
|
| 85 |
+
Generate/export the quality report and return a file path for download.
|
| 86 |
Tries to find an existing ZIP; otherwise saves a TXT fallback.
|
| 87 |
"""
|
| 88 |
if not self.generator:
|
|
|
|
| 183 |
return synthetic_df, f"{status}: {message}"
|
| 184 |
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
def create_comparison_plot(original_df: pd.DataFrame, synthetic_df: pd.DataFrame) -> Optional[go.Figure]:
|
| 187 |
if original_df is None or synthetic_df is None:
|
| 188 |
return None
|
|
|
|
| 287 |
train_btn = gr.Button("Train Model", variant="primary")
|
| 288 |
with gr.Column():
|
| 289 |
train_status = gr.Textbox(label="Training Status", interactive=False)
|
|
|
|
| 290 |
|
| 291 |
with gr.Row():
|
| 292 |
+
get_report_btn = gr.DownloadButton("Get Quality Report", variant="secondary")
|
|
|
|
| 293 |
|
| 294 |
with gr.Tab("Generate Data"):
|
| 295 |
gr.Markdown("### Generate synthetic data from your trained model")
|
|
|
|
| 305 |
download_btn = gr.DownloadButton("Download CSV", variant="secondary")
|
| 306 |
comparison_plot = gr.Plot(label="Data Comparison")
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
# ---- Event handlers ----
|
| 309 |
init_btn.click(initialize_sdk, outputs=[init_status])
|
| 310 |
|
|
|
|
| 314 |
outputs=[train_status],
|
| 315 |
)
|
| 316 |
|
| 317 |
+
# Direct download of quality report
|
| 318 |
+
get_report_btn.click(generator.get_quality_report_file, outputs=[get_report_btn])
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
# Generate data
|
| 321 |
generate_btn.click(generate_data, inputs=[gen_size], outputs=[synthetic_data, gen_status])
|