Spaces:
Runtime error
Runtime error
123
Browse files- app.py +32 -7
- data_experiments.py +1 -0
app.py
CHANGED
|
@@ -22,7 +22,7 @@ from transformers import (
|
|
| 22 |
)
|
| 23 |
from transformers.image_utils import load_image
|
| 24 |
|
| 25 |
-
from data_experiments import filter_experiments
|
| 26 |
|
| 27 |
# Constants for text generation
|
| 28 |
MAX_MAX_NEW_TOKENS = 2048
|
|
@@ -105,10 +105,15 @@ def process_image(
|
|
| 105 |
yield buffer, buffer
|
| 106 |
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
def format_experiment_dropdown_title(experiment: dict) -> str:
|
| 114 |
id = str(experiment["id"])
|
|
@@ -116,6 +121,13 @@ def format_experiment_dropdown_title(experiment: dict) -> str:
|
|
| 116 |
product = experiment.get("product_id", "")
|
| 117 |
return f"{id}. {title} ({product})"
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
css = """
|
| 120 |
.submit-btn {
|
| 121 |
background-color: #2980b9 !important;
|
|
@@ -136,8 +148,13 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
| 136 |
gr.Markdown("# **Experiments photo moderation**")
|
| 137 |
with gr.Row():
|
| 138 |
with gr.Column():
|
| 139 |
-
gr.Dropdown(
|
| 140 |
-
choices=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
value=None,
|
| 142 |
label="Select Experiment",
|
| 143 |
)
|
|
@@ -164,11 +181,19 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
| 164 |
with gr.Accordion("(Result.md)", open=False):
|
| 165 |
markdown_output = gr.Markdown()
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
image_submit.click(
|
| 168 |
fn=process_image,
|
| 169 |
inputs=[model_choice, image_query, image_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
|
| 170 |
outputs=[output, markdown_output]
|
| 171 |
)
|
| 172 |
|
|
|
|
|
|
|
| 173 |
if __name__ == "__main__":
|
| 174 |
demo.queue(max_size=30).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)
|
|
|
|
| 22 |
)
|
| 23 |
from transformers.image_utils import load_image
|
| 24 |
|
| 25 |
+
from data_experiments import all_products, all_experiments, filter_experiments
|
| 26 |
|
| 27 |
# Constants for text generation
|
| 28 |
MAX_MAX_NEW_TOKENS = 2048
|
|
|
|
| 105 |
yield buffer, buffer
|
| 106 |
|
| 107 |
|
| 108 |
+
|
| 109 |
+
products_for_dropdown = sorted(all_products)
|
| 110 |
+
|
| 111 |
+
def build_experiments_for_dropdown(product: str) -> list[dict]:
|
| 112 |
+
experiments = filter_experiments(
|
| 113 |
+
experiments=all_experiments,
|
| 114 |
+
product_id=product,
|
| 115 |
+
)
|
| 116 |
+
return sorted(experiments, key=lambda x: x["id"])
|
| 117 |
|
| 118 |
def format_experiment_dropdown_title(experiment: dict) -> str:
|
| 119 |
id = str(experiment["id"])
|
|
|
|
| 121 |
product = experiment.get("product_id", "")
|
| 122 |
return f"{id}. {title} ({product})"
|
| 123 |
|
| 124 |
+
def update_experiments_dropdown(product: str):
|
| 125 |
+
experiments = build_experiments_for_dropdown(product)
|
| 126 |
+
return gr.update(
|
| 127 |
+
choices=[(format_experiment_dropdown_title(exp), exp["id"]) for exp in experiments],
|
| 128 |
+
value=experiments[0]["id"] if experiments else None,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
css = """
|
| 132 |
.submit-btn {
|
| 133 |
background-color: #2980b9 !important;
|
|
|
|
| 148 |
gr.Markdown("# **Experiments photo moderation**")
|
| 149 |
with gr.Row():
|
| 150 |
with gr.Column():
|
| 151 |
+
product_dropdown = gr.Dropdown(
|
| 152 |
+
choices=products_for_dropdown,
|
| 153 |
+
value="chemistry",
|
| 154 |
+
label="Select Product",
|
| 155 |
+
)
|
| 156 |
+
experiment_dropdown = gr.Dropdown(
|
| 157 |
+
choices=[],
|
| 158 |
value=None,
|
| 159 |
label="Select Experiment",
|
| 160 |
)
|
|
|
|
| 181 |
with gr.Accordion("(Result.md)", open=False):
|
| 182 |
markdown_output = gr.Markdown()
|
| 183 |
|
| 184 |
+
product_dropdown.change(
|
| 185 |
+
fn=update_experiments_dropdown,
|
| 186 |
+
inputs=product_dropdown,
|
| 187 |
+
outputs=experiment_dropdown
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
image_submit.click(
|
| 191 |
fn=process_image,
|
| 192 |
inputs=[model_choice, image_query, image_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
|
| 193 |
outputs=[output, markdown_output]
|
| 194 |
)
|
| 195 |
|
| 196 |
+
update_experiments_dropdown("chemistry") # Initial load for default product
|
| 197 |
+
|
| 198 |
if __name__ == "__main__":
|
| 199 |
demo.queue(max_size=30).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)
|
data_experiments.py
CHANGED
|
@@ -12,6 +12,7 @@ for experiment in all_experiments:
|
|
| 12 |
if product_id is not None:
|
| 13 |
experiment_ids_by_product_id[product_id].append(experiment["id"])
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
def get_experiment_by_id(experiment_id: int) -> Union[dict, None]:
|
| 17 |
for experiment in all_experiments:
|
|
|
|
| 12 |
if product_id is not None:
|
| 13 |
experiment_ids_by_product_id[product_id].append(experiment["id"])
|
| 14 |
|
| 15 |
+
all_products = list(experiment_ids_by_product_id.keys())
|
| 16 |
|
| 17 |
def get_experiment_by_id(experiment_id: int) -> Union[dict, None]:
|
| 18 |
for experiment in all_experiments:
|