Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,16 @@ from requests.exceptions import RequestException
|
|
| 15 |
with open('index.html', 'r', encoding='utf-8') as file:
|
| 16 |
cheatsheet_template = file.read()
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
@tool
|
| 19 |
def json_string_to_poster(json_string:str)-> str:
|
| 20 |
"""A tool that generate a poster from stringified json object
|
|
@@ -25,11 +35,7 @@ def json_string_to_poster(json_string:str)-> str:
|
|
| 25 |
#html_template = cheatsheet_template.replace('%cheatsheet%', json_string)
|
| 26 |
|
| 27 |
html_template = f"""
|
| 28 |
-
<div id="root"></div>
|
| 29 |
-
<script>
|
| 30 |
-
console.log('Running script');
|
| 31 |
-
document.getElementById("root").innerHTML = {json_string};
|
| 32 |
-
</script>
|
| 33 |
"""
|
| 34 |
|
| 35 |
return html_template
|
|
@@ -86,6 +92,7 @@ with gr.Blocks() as demo:
|
|
| 86 |
inputs=city_input,
|
| 87 |
outputs=poster_display
|
| 88 |
)
|
|
|
|
| 89 |
|
| 90 |
# Для HuggingFace Spaces
|
| 91 |
demo.launch()
|
|
|
|
| 15 |
with open('index.html', 'r', encoding='utf-8') as file:
|
| 16 |
cheatsheet_template = file.read()
|
| 17 |
|
| 18 |
+
|
| 19 |
+
scripts = """
|
| 20 |
+
async () => {
|
| 21 |
+
console.log('Running script');
|
| 22 |
+
const json_obj = JSON.parse(document.getElementById("root").innerHTML);
|
| 23 |
+
console.log(json_obj)
|
| 24 |
+
document.getElementById("root").innerHTML += 'Hello!'
|
| 25 |
+
}
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
@tool
|
| 29 |
def json_string_to_poster(json_string:str)-> str:
|
| 30 |
"""A tool that generate a poster from stringified json object
|
|
|
|
| 35 |
#html_template = cheatsheet_template.replace('%cheatsheet%', json_string)
|
| 36 |
|
| 37 |
html_template = f"""
|
| 38 |
+
<div id="root">{json_string}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"""
|
| 40 |
|
| 41 |
return html_template
|
|
|
|
| 92 |
inputs=city_input,
|
| 93 |
outputs=poster_display
|
| 94 |
)
|
| 95 |
+
demo.load(None,None,None,_js=scripts)
|
| 96 |
|
| 97 |
# Для HuggingFace Spaces
|
| 98 |
demo.launch()
|