Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ import datetime
|
|
| 12 |
from pypdf import PdfReader
|
| 13 |
import uuid
|
| 14 |
from PIL import Image
|
|
|
|
| 15 |
from agent import (
|
| 16 |
PREFIX,
|
| 17 |
GET_CHART,
|
|
@@ -441,7 +442,36 @@ def create_image(url):
|
|
| 441 |
#output = cairosvg.svg2png(
|
| 442 |
# bytestring=open('tmp.svg').read().encode('utf-8'), write_to="output.png")
|
| 443 |
return "tmp.png"
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
score_js="""
|
| 446 |
function(text_input) {
|
| 447 |
console.log(text_input);
|
|
@@ -503,7 +533,8 @@ with gr.Blocks() as app:
|
|
| 503 |
def return_score(text):
|
| 504 |
print(text)
|
| 505 |
return text
|
| 506 |
-
create_im.click(
|
|
|
|
| 507 |
#zoom_btn.change(zoom_update,zoom_btn,None)
|
| 508 |
upd_button.click(mm,[e_box,zoom_btn],[m_box,url_box])
|
| 509 |
#inp_query.change(search_models,inp_query,models_dd)
|
|
|
|
| 12 |
from pypdf import PdfReader
|
| 13 |
import uuid
|
| 14 |
from PIL import Image
|
| 15 |
+
|
| 16 |
from agent import (
|
| 17 |
PREFIX,
|
| 18 |
GET_CHART,
|
|
|
|
| 442 |
#output = cairosvg.svg2png(
|
| 443 |
# bytestring=open('tmp.svg').read().encode('utf-8'), write_to="output.png")
|
| 444 |
return "tmp.png"
|
| 445 |
+
|
| 446 |
+
def create_ss(graph):
|
| 447 |
+
uid=uuid.uuid4()
|
| 448 |
+
code_out=""
|
| 449 |
+
for ea in graph.split("\n"):
|
| 450 |
+
code=ea.strip().strip("\n")
|
| 451 |
+
code_out+=code
|
| 452 |
+
url=f"https://omnibus-text-to-chart.hf.space/file=merm.html?mermaid={code_out}"
|
| 453 |
+
is_url=True
|
| 454 |
+
wait_time=10000
|
| 455 |
+
if is_url:
|
| 456 |
+
options = webdriver.ChromeOptions()
|
| 457 |
+
options.add_argument('--headless')
|
| 458 |
+
options.add_argument('--no-sandbox')
|
| 459 |
+
options.add_argument('--disable-dev-shm-usage')
|
| 460 |
+
mes='<center>operation success'
|
| 461 |
+
try:
|
| 462 |
+
driver = webdriver.Chrome(options=options)
|
| 463 |
+
driver.get(url)
|
| 464 |
+
html=driver.page_source
|
| 465 |
+
print(html)
|
| 466 |
+
driver.implicitly_wait(int(wait_time*30))
|
| 467 |
+
driver.set_window_size(int(width), int(height))
|
| 468 |
+
obj = driver.find_element(By.ID, "char_box")
|
| 469 |
+
screenshot = obj.screenshot(f'{uid}-tmp.png')
|
| 470 |
+
return(f'{uid}-tmp.png')
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
|
| 475 |
score_js="""
|
| 476 |
function(text_input) {
|
| 477 |
console.log(text_input);
|
|
|
|
| 533 |
def return_score(text):
|
| 534 |
print(text)
|
| 535 |
return text
|
| 536 |
+
create_im.click(create_ss,e_box,svg_img)
|
| 537 |
+
#create_im.click(return_score,score,[score],_js=score_js).then(create_image,score,svg_img)
|
| 538 |
#zoom_btn.change(zoom_update,zoom_btn,None)
|
| 539 |
upd_button.click(mm,[e_box,zoom_btn],[m_box,url_box])
|
| 540 |
#inp_query.change(search_models,inp_query,models_dd)
|