Skip to content

Instantly share code, notes, and snippets.

@patryk-oleniuk
Last active May 11, 2020 03:47
Show Gist options
  • Save patryk-oleniuk/c2ed5ba9b9f1531583a4339bb966cd15 to your computer and use it in GitHub Desktop.
Save patryk-oleniuk/c2ed5ba9b9f1531583a4339bb966cd15 to your computer and use it in GitHub Desktop.
Creating a bunch of test files, and then logging then into mlflow experiment
import json
import plotly.express as px
import mlflow
import requests
### prepare sample files to log
# test data
df = px.data.iris()
# sample CSV file
df.to_csv("1_data_sample.csv")
# sample pandas HTML file
df.to_html("2_data_sample.html")
# sample image
r = requests.get("https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png")
with open("3_image_sample.png", 'wb') as f:
f.write(r.content)
# sample gif
r = requests.get("https://media1.giphy.com/media/bU3YVJAAXckCI/giphy.gif")
with open("4_gif_sample.gif", 'wb') as f:
f.write(r.content)
# sample plotly plot - HTML
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", marginal_y="rug", marginal_x="histogram")
fig.write_html("5_plot_sample.html")
# sample geojson
with open("6_map_sample.geojson", "w+") as f:
data = requests.get("https://gist.githubusercontent.com/wavded/1200773/raw/e122cf709898c09758aecfef349964a8d73a83f3/sample.json").json()
f.write(json.dumps(data))
### log files to mlflow experiment
with mlflow.start_run(experiment_id=1, run_name="file_display") as run:
mlflow.log_param("parameter","test")
mlflow.log_metric("the_answer",42.0)
mlflow.log_artifact("./1_data_sample.csv")
mlflow.log_artifact("./2_data_sample.html")
mlflow.log_artifact("./3_image_sample.png")
mlflow.log_artifact("./4_gif_sample.gif")
mlflow.log_artifact("./5_plot_sample.html")
mlflow.log_artifact("./6_map_sample.geojson")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment