Spaces:
Running
Running
move logging to its own module
Browse files- app.py +9 -76
- logging.py +74 -0
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import uuid
|
|
|
2 |
|
3 |
-
import comet_ml
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
from PIL import Image
|
@@ -16,82 +16,15 @@ You can use this Space to log predictions to [Comet](https://www.comet.ml/site)
|
|
16 |
|
17 |
Keep track of all your prompts and generated images so that you remember the good ones!
|
18 |
|
19 |
-
Set your Comet credentials in the Comet Settings tab and create an Experiment for logging data.
|
20 |
-
|
21 |
-
|
22 |
-
Then use the path to a Space to generate from in the Diffusion Model tab
|
23 |
-
"""
|
24 |
|
|
|
25 |
|
26 |
-
|
27 |
-
comet_api_key,
|
28 |
-
comet_workspace,
|
29 |
-
comet_project_name,
|
30 |
-
comet_experiment_name,
|
31 |
-
experiment,
|
32 |
-
):
|
33 |
-
if not comet_api_key:
|
34 |
-
experiment = None
|
35 |
-
return (
|
36 |
-
experiment,
|
37 |
-
"""
|
38 |
-
Please add your API key in order to log your predictions to a Comet Experiment.
|
39 |
-
If you don't have a Comet account yet, you can sign up using the link below:
|
40 |
-
|
41 |
-
https://www.comet.ml/signup
|
42 |
-
""",
|
43 |
-
)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
api_experiment = get_experiment(
|
48 |
-
{
|
49 |
-
"api_key": comet_api_key,
|
50 |
-
"workspace": comet_workspace,
|
51 |
-
"project_name": comet_project_name,
|
52 |
-
"experiment": comet_experiment_name,
|
53 |
-
}
|
54 |
-
)
|
55 |
-
else:
|
56 |
-
api_experiment = comet_ml.APIExperiment(
|
57 |
-
api_key=comet_api_key,
|
58 |
-
workspace=comet_workspace,
|
59 |
-
project_name=comet_project_name,
|
60 |
-
)
|
61 |
-
experiment = {
|
62 |
-
"api_key": comet_api_key,
|
63 |
-
"workspace": comet_workspace,
|
64 |
-
"project_name": comet_project_name,
|
65 |
-
"experiment": api_experiment.name,
|
66 |
-
}
|
67 |
-
|
68 |
-
return experiment, f"Started {api_experiment.name}. Happy logging!π"
|
69 |
-
|
70 |
-
except Exception as e:
|
71 |
-
return None, e
|
72 |
-
|
73 |
-
|
74 |
-
def get_experiment(experiment_state):
|
75 |
-
try:
|
76 |
-
api_key = experiment_state.get("api_key")
|
77 |
-
workspace = experiment_state.get("workspace")
|
78 |
-
project = experiment_state.get("project_name")
|
79 |
-
experiment_name = experiment_state.get("experiment")
|
80 |
-
|
81 |
-
return comet_ml.API(api_key=api_key).get_experiment(
|
82 |
-
workspace=workspace, project_name=project, experiment=experiment_name
|
83 |
-
)
|
84 |
-
except Exception as e:
|
85 |
-
return None
|
86 |
-
|
87 |
-
|
88 |
-
def get_experiment_status(experiment_state):
|
89 |
-
experiment = get_experiment(experiment_state)
|
90 |
-
if experiment is not None:
|
91 |
-
name = experiment.name
|
92 |
-
return experiment_state, f"Currently logging to: {name}"
|
93 |
-
|
94 |
-
return experiment_state, f"No Experiments found"
|
95 |
|
96 |
|
97 |
def predict(
|
@@ -184,8 +117,8 @@ def start_interface():
|
|
184 |
only text as input and produces an image as an output
|
185 |
"""
|
186 |
)
|
187 |
-
model = gr.Textbox(label="Model", value="spaces/valhalla/glide-text2im")
|
188 |
-
prompt = gr.Textbox(label="Prompt")
|
189 |
|
190 |
outputs = gr.Image(label="Image")
|
191 |
|
|
|
1 |
import uuid
|
2 |
+
from logging import get_experiment, get_experiment_status, start_experiment
|
3 |
|
|
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
from PIL import Image
|
|
|
16 |
|
17 |
Keep track of all your prompts and generated images so that you remember the good ones!
|
18 |
|
19 |
+
Set your Comet credentials in the Comet Settings tab and create an Experiment for logging data. If you don't have credentials yet,
|
20 |
+
you can [sign up for Comet here](https://www.comet.ml/signup)
|
|
|
|
|
|
|
21 |
|
22 |
+
If you want to continue logging to the same Experiment over multiple sessions, simply provide the experiment name.
|
23 |
|
24 |
+
Set a path to a Space using that uses a Diffusion model and submit your prompt in the Diffusion Model tab
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
** Note: ** This Space will still run even if you don't set credentials
|
27 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
|
30 |
def predict(
|
|
|
117 |
only text as input and produces an image as an output
|
118 |
"""
|
119 |
)
|
120 |
+
model = gr.Textbox(label="Model", value="spaces/valhalla/glide-text2im", placeholder="Enter a path to a Space")
|
121 |
+
prompt = gr.Textbox(label="Prompt", value="an oil painting of a corgi", placeholder="Enter your text prompt here")
|
122 |
|
123 |
outputs = gr.Image(label="Image")
|
124 |
|
logging.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import comet_ml
|
2 |
+
|
3 |
+
|
4 |
+
def start_experiment(
|
5 |
+
comet_api_key,
|
6 |
+
comet_workspace,
|
7 |
+
comet_project_name,
|
8 |
+
comet_experiment_name,
|
9 |
+
experiment,
|
10 |
+
):
|
11 |
+
if comet_api_key is None:
|
12 |
+
experiment = None
|
13 |
+
return (
|
14 |
+
experiment,
|
15 |
+
"""
|
16 |
+
Please add your API key in order to log your predictions to a Comet Experiment.
|
17 |
+
If you don't have a Comet account yet, you can sign up using the link below:
|
18 |
+
|
19 |
+
https://www.comet.ml/signup
|
20 |
+
""",
|
21 |
+
)
|
22 |
+
|
23 |
+
try:
|
24 |
+
if comet_experiment_name:
|
25 |
+
# Retrieve the Experiment if it already exists
|
26 |
+
api_experiment = get_experiment(
|
27 |
+
{
|
28 |
+
"api_key": comet_api_key,
|
29 |
+
"workspace": comet_workspace,
|
30 |
+
"project_name": comet_project_name,
|
31 |
+
"experiment": comet_experiment_name,
|
32 |
+
}
|
33 |
+
)
|
34 |
+
else:
|
35 |
+
# Create a new Experiment
|
36 |
+
api_experiment = comet_ml.APIExperiment(
|
37 |
+
api_key=comet_api_key,
|
38 |
+
workspace=comet_workspace,
|
39 |
+
project_name=comet_project_name,
|
40 |
+
)
|
41 |
+
experiment = {
|
42 |
+
"api_key": comet_api_key,
|
43 |
+
"workspace": comet_workspace,
|
44 |
+
"project_name": comet_project_name,
|
45 |
+
"experiment": api_experiment.name,
|
46 |
+
}
|
47 |
+
|
48 |
+
return experiment, f"Started {api_experiment.name}. Happy logging!π"
|
49 |
+
|
50 |
+
except Exception as e:
|
51 |
+
return None, e
|
52 |
+
|
53 |
+
|
54 |
+
def get_experiment(experiment_state):
|
55 |
+
try:
|
56 |
+
api_key = experiment_state.get("api_key")
|
57 |
+
workspace = experiment_state.get("workspace")
|
58 |
+
project = experiment_state.get("project_name")
|
59 |
+
experiment_name = experiment_state.get("experiment")
|
60 |
+
|
61 |
+
return comet_ml.API(api_key=api_key).get_experiment(
|
62 |
+
workspace=workspace, project_name=project, experiment=experiment_name
|
63 |
+
)
|
64 |
+
except Exception as e:
|
65 |
+
return None
|
66 |
+
|
67 |
+
|
68 |
+
def get_experiment_status(experiment_state):
|
69 |
+
experiment = get_experiment(experiment_state)
|
70 |
+
if experiment is not None:
|
71 |
+
name = experiment.name
|
72 |
+
return experiment_state, f"Currently logging to: {name}"
|
73 |
+
|
74 |
+
return experiment_state, f"No Experiments found"
|