adding sharing link and history
Browse files
app.py
CHANGED
@@ -23,6 +23,17 @@ from diffusers import AutoencoderKL
|
|
23 |
import pandas as pd
|
24 |
import base64
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def load_app_config():
|
27 |
global appConfig
|
28 |
try:
|
@@ -34,7 +45,7 @@ def load_app_config():
|
|
34 |
print("Error decoding JSON in app config file.")
|
35 |
except Exception as e:
|
36 |
print("An error occurred while loading app config:", str(e))
|
37 |
-
|
38 |
load_app_config()
|
39 |
|
40 |
# code output order
|
@@ -104,6 +115,7 @@ current_config = {
|
|
104 |
"prompt": prompt,
|
105 |
"negative_prompt": negative_prompt,
|
106 |
}
|
|
|
107 |
config_history = [current_config]
|
108 |
|
109 |
def get_sorted_code():
|
@@ -307,36 +319,26 @@ code[code_pos_run_inference] = f'''image = pipeline(
|
|
307 |
generator=generator.manual_seed(manual_seed),
|
308 |
num_inference_steps=inference_steps,
|
309 |
guidance_scale=guidance_scale).images[0]'''
|
310 |
-
|
311 |
def dict_list_to_markdown_table(data):
|
312 |
if not data:
|
313 |
return ""
|
314 |
|
315 |
headers = list(data[0].keys())
|
316 |
-
markdown_table = "|
|
317 |
markdown_table += "| --- | " + " | ".join(["---"] * len(headers)) + " |\n"
|
318 |
|
319 |
for i, row in enumerate(data):
|
320 |
-
# Encode row's content in base64 for sharing
|
321 |
encoded_row = base64.b64encode(str(row).encode()).decode()
|
322 |
-
|
323 |
-
share_link = f'<a href="share/{encoded_row}">π</a>'
|
324 |
-
# Create link to remove the row
|
325 |
-
remove_link = f'<a href="remove/{i}">β</a>'
|
326 |
# Construct the row with links
|
327 |
-
markdown_table += f"| {share_link}
|
328 |
|
329 |
# Wrap the Markdown table in a <div> tag with horizontal scrolling
|
330 |
markdown_table = '<div style="overflow-x: auto;">\n\n' + markdown_table + '</div>'
|
331 |
|
332 |
return markdown_table
|
333 |
|
334 |
-
@app.route('/remove/<int:index>')
|
335 |
-
def remove_row(index):
|
336 |
-
if 0 <= index < len(data):
|
337 |
-
del data[index]
|
338 |
-
return "Row removed successfully"
|
339 |
-
|
340 |
# interface
|
341 |
with gr.Blocks() as demo:
|
342 |
|
|
|
23 |
import pandas as pd
|
24 |
import base64
|
25 |
|
26 |
+
js_get_url_parameters = """console.log(window.location);
|
27 |
+
var urlParams = new URLSearchParams(window.location.hash.substr(1));
|
28 |
+
var decodedParams = {};
|
29 |
+
console.log(window.location);
|
30 |
+
urlParams.forEach(function(value, key) {
|
31 |
+
var decodedValue = atob(value);
|
32 |
+
decodedParams[key] = decodedValue;
|
33 |
+
});
|
34 |
+
console.log(JSON.stringify(decodedParams));
|
35 |
+
"""
|
36 |
+
|
37 |
def load_app_config():
|
38 |
global appConfig
|
39 |
try:
|
|
|
45 |
print("Error decoding JSON in app config file.")
|
46 |
except Exception as e:
|
47 |
print("An error occurred while loading app config:", str(e))
|
48 |
+
|
49 |
load_app_config()
|
50 |
|
51 |
# code output order
|
|
|
115 |
"prompt": prompt,
|
116 |
"negative_prompt": negative_prompt,
|
117 |
}
|
118 |
+
|
119 |
config_history = [current_config]
|
120 |
|
121 |
def get_sorted_code():
|
|
|
319 |
generator=generator.manual_seed(manual_seed),
|
320 |
num_inference_steps=inference_steps,
|
321 |
guidance_scale=guidance_scale).images[0]'''
|
322 |
+
|
323 |
def dict_list_to_markdown_table(data):
|
324 |
if not data:
|
325 |
return ""
|
326 |
|
327 |
headers = list(data[0].keys())
|
328 |
+
markdown_table = "| share | " + " | ".join(headers) + " |\n"
|
329 |
markdown_table += "| --- | " + " | ".join(["---"] * len(headers)) + " |\n"
|
330 |
|
331 |
for i, row in enumerate(data):
|
|
|
332 |
encoded_row = base64.b64encode(str(row).encode()).decode()
|
333 |
+
share_link = f'<a href="#share/{encoded_row}">π</a>'
|
|
|
|
|
|
|
334 |
# Construct the row with links
|
335 |
+
markdown_table += f"| {share_link} | " + " | ".join(str(row.get(key, "")) for key in headers) + " |\n"
|
336 |
|
337 |
# Wrap the Markdown table in a <div> tag with horizontal scrolling
|
338 |
markdown_table = '<div style="overflow-x: auto;">\n\n' + markdown_table + '</div>'
|
339 |
|
340 |
return markdown_table
|
341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
# interface
|
343 |
with gr.Blocks() as demo:
|
344 |
|