Omnibus commited on
Commit
f59ebbe
1 Parent(s): 29d9173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -411,8 +411,9 @@ def mm(graph,zoom):
411
  code=ea.strip().strip("\n")
412
  code_out+=code
413
  #out_html=f'''<div><iframe src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}&rand={random.randint(1,1111111111)}" height="500" width="500"></iframe></div>'''
414
- out_html=f'''<div id="wrap" style="width: 100%; height: 100%;max-height:600px; padding: 0; overflow: auto;"><iframe id="frame" src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}" style="width:100%; height:600px; border: 1px solid black; zoom: {str(zoom)}; -moz-transform: scale({str(zoom)}); -moz-transform-origin: 0 0;"></iframe></div>'''
415
- return out_html
 
416
 
417
  def summarize(inp,history,data=None,files=None,directory=None,url=None,pdf_url=None,pdf_batch=None):
418
  json_box=[]
@@ -538,8 +539,24 @@ def summarize(inp,history,data=None,files=None,directory=None,url=None,pdf_url=N
538
  def clear_fn():
539
  return "",[(None,None)]
540
 
541
-
542
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  def zoom_update(inp):
544
  this.clear()
545
  this.append(str(inp))
@@ -575,12 +592,18 @@ with gr.Blocks() as app:
575
  m_box=gr.HTML()
576
  zoom_btn=gr.Slider(label="Zoom",step=0.01,minimum=0.1,maximum=20,value=1,interactive=True)
577
  e_box=gr.Textbox(interactive=True)
578
- upd_button=gr.Button("Update Chart")
 
 
 
 
 
579
  json_out=gr.JSON()
580
  #text=gr.JSON()
581
 
 
582
  #zoom_btn.change(zoom_update,zoom_btn,None)
583
- upd_button.click(mm,[e_box,zoom_btn],[m_box])
584
  #inp_query.change(search_models,inp_query,models_dd)
585
  clear_btn.click(clear_fn,None,[prompt,chatbot])
586
 
 
411
  code=ea.strip().strip("\n")
412
  code_out+=code
413
  #out_html=f'''<div><iframe src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}&rand={random.randint(1,1111111111)}" height="500" width="500"></iframe></div>'''
414
+ url=f"https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}"
415
+ out_html=f'''<div id="wrap" style="width: 100%; height: 100%;max-height:600px; padding: 0; overflow: auto;"><iframe id="frame" src="{url}" style="width:100%; height:600px; border: 1px solid black; zoom: {str(zoom)}; -moz-transform: scale({str(zoom)}); -moz-transform-origin: 0 0;"></iframe></div>'''
416
+ return out_html,url
417
 
418
  def summarize(inp,history,data=None,files=None,directory=None,url=None,pdf_url=None,pdf_batch=None):
419
  json_box=[]
 
539
  def clear_fn():
540
  return "",[(None,None)]
541
 
542
+ def create_image(url):
543
+ source = requests.get(url)
544
+ #source = urllib.request.urlopen(url).read()
545
+ soup = bs4.BeautifulSoup(source.content,'lxml')
546
+
547
+ #rawp=(f'RAW TEXT RETURNED: {soup.text}')
548
+ #cnt=0
549
+ #cnt+=len(rawp)
550
+ #out.append(rawp)
551
+ #out.append("HTML fragments: ")
552
+ #q=("a","p","span","content","article")
553
+ out=[]
554
+ for p in soup.find_all("svg"):
555
+ print(p)
556
+ out.append(p.string)
557
+ with open("tmp.svg","w") as svg:
558
+ svg.write(out[0])
559
+ return "tmp.svg"
560
  def zoom_update(inp):
561
  this.clear()
562
  this.append(str(inp))
 
592
  m_box=gr.HTML()
593
  zoom_btn=gr.Slider(label="Zoom",step=0.01,minimum=0.1,maximum=20,value=1,interactive=True)
594
  e_box=gr.Textbox(interactive=True)
595
+ with gr.Row():
596
+ upd_button=gr.Button("Update Chart")
597
+ create_im=gr.Button("Create Image")
598
+ svg_img=gr.Image()
599
+ url_box=gr.Textbox()
600
+
601
  json_out=gr.JSON()
602
  #text=gr.JSON()
603
 
604
+ create_im.click(create_image,url_box,svg_img)
605
  #zoom_btn.change(zoom_update,zoom_btn,None)
606
+ upd_button.click(mm,[e_box,zoom_btn],[m_box,url_box])
607
  #inp_query.change(search_models,inp_query,models_dd)
608
  clear_btn.click(clear_fn,None,[prompt,chatbot])
609