datasciencedojo commited on
Commit
163653e
·
1 Parent(s): 8822117

zoom functionality added

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -15,7 +15,7 @@ def render_dep_chart(doc):
15
  img.write(svg.encode())
16
  img.seek(0)
17
  b64 = base64.b64encode(img.read()).decode()
18
- return f"<img id='zoomable' src='data:image/svg+xml;base64,{b64}'/>"
19
 
20
  def text_analysis(text):
21
  doc = nlp(text)
@@ -43,12 +43,30 @@ footer {display:none !important}
43
  --tw-bg-opacity: 1 !important;
44
  background-color: rgb(229,225,255) !important;
45
  }
46
- #zoomable{
47
- pointer: cursor;
48
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  """
50
 
51
- with gr.Blocks(title="Analyze Text | Data Science Dojo", css = css) as demo:
52
  with gr.Row():
53
  inp = gr.Textbox(placeholder="Enter text to analyze...", label="Input")
54
  btn = gr.Button("Analyze Text")
@@ -66,4 +84,4 @@ with gr.Blocks(title="Analyze Text | Data Science Dojo", css = css) as demo:
66
  ["It's the best time to execute the plan."],
67
  ], fn=text_analysis, inputs=inp, outputs=[table, visual1], cache_examples=True)
68
  btn.click(fn=text_analysis, inputs=inp, outputs=[table, visual1])
69
- demo.launch()
 
15
  img.write(svg.encode())
16
  img.seek(0)
17
  b64 = base64.b64encode(img.read()).decode()
18
+ return f"<img id='zoomable' class='zoomable-image' src='data:image/svg+xml;base64,{b64}'/>"
19
 
20
  def text_analysis(text):
21
  doc = nlp(text)
 
43
  --tw-bg-opacity: 1 !important;
44
  background-color: rgb(229,225,255) !important;
45
  }
46
+ .zoomable-image {
47
+ cursor: pointer;
48
  }
49
+ .zoomed-image {
50
+ position: fixed;
51
+ top: 0;
52
+ left: 0;
53
+ width: 100%;
54
+ height: 100%;
55
+ object-fit: contain;
56
+ z-index: 99999;
57
+ background: rgba(0,0,0,0.8);
58
+ }
59
+ """
60
+
61
+ js = """
62
+ document.querySelectorAll('.zoomable-image').forEach((image) => {
63
+ image.addEventListener('click', () => {
64
+ image.classList.toggle('zoomed-image');
65
+ });
66
+ });
67
  """
68
 
69
+ with gr.Blocks(title="Analyze Text | Data Science Dojo", css = css, js=js) as demo:
70
  with gr.Row():
71
  inp = gr.Textbox(placeholder="Enter text to analyze...", label="Input")
72
  btn = gr.Button("Analyze Text")
 
84
  ["It's the best time to execute the plan."],
85
  ], fn=text_analysis, inputs=inp, outputs=[table, visual1], cache_examples=True)
86
  btn.click(fn=text_analysis, inputs=inp, outputs=[table, visual1])
87
+ demo.launch()