Spaces:
Sleeping
Sleeping
omkarenator
commited on
Commit
•
a08395c
1
Parent(s):
6c4dc6d
incorporate plotly
Browse files
main.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
from fasthtml.common import *
|
2 |
from fasthtml.components import *
|
3 |
from fasthtml.components import D_title, D_article, D_front_matter, D_contents, D_byline
|
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
-
app, rt = fast_app(
|
7 |
|
8 |
|
9 |
@app.get("/")
|
@@ -12,9 +16,10 @@ def main():
|
|
12 |
Head(
|
13 |
Meta(charset="UTF-8"),
|
14 |
Meta(name="viewport", content="width=device-width, initial-scale=1.0"),
|
15 |
-
Link(rel="stylesheet", href="style.css"),
|
16 |
Script(src="https://distill.pub/template.v2.js"),
|
17 |
Script(src="https://unpkg.com/htmx.org@next/dist/htmx.min.js"),
|
|
|
|
|
18 |
),
|
19 |
Body(
|
20 |
D_title(
|
@@ -76,12 +81,24 @@ def main():
|
|
76 |
),
|
77 |
Div(
|
78 |
A("Web Data", href="#inner-text"),
|
79 |
-
hx_get="/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
hx_target="#inner-text",
|
81 |
),
|
82 |
-
Div(A("Curated Sources")),
|
83 |
-
Div(A("Common Steps")),
|
84 |
-
Div(A("TxT360 Results")),
|
85 |
role="navigation",
|
86 |
cls="l-text figcaption",
|
87 |
),
|
@@ -235,9 +252,73 @@ def intro():
|
|
235 |
)
|
236 |
|
237 |
|
238 |
-
@app.get("/
|
239 |
def web_data():
|
240 |
return Div(Section(H2(P("Web Data")), id="inner-text"))
|
241 |
|
242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
serve()
|
|
|
1 |
from fasthtml.common import *
|
2 |
from fasthtml.components import *
|
3 |
from fasthtml.components import D_title, D_article, D_front_matter, D_contents, D_byline
|
4 |
+
from plotly import graph_objects as go
|
5 |
+
from fh_plotly import plotly2fasthtml
|
6 |
+
import pandas as pd
|
7 |
+
import json
|
8 |
|
9 |
|
10 |
+
app, rt = fast_app(debug=True)
|
11 |
|
12 |
|
13 |
@app.get("/")
|
|
|
16 |
Head(
|
17 |
Meta(charset="UTF-8"),
|
18 |
Meta(name="viewport", content="width=device-width, initial-scale=1.0"),
|
|
|
19 |
Script(src="https://distill.pub/template.v2.js"),
|
20 |
Script(src="https://unpkg.com/htmx.org@next/dist/htmx.min.js"),
|
21 |
+
Script(src="https://cdn.plot.ly/plotly-latest.min.js"),
|
22 |
+
Link(rel="stylesheet", href="style.css"),
|
23 |
),
|
24 |
Body(
|
25 |
D_title(
|
|
|
81 |
),
|
82 |
Div(
|
83 |
A("Web Data", href="#inner-text"),
|
84 |
+
hx_get="/webdata",
|
85 |
+
hx_target="#inner-text",
|
86 |
+
),
|
87 |
+
Div(
|
88 |
+
A("Curated Sources", href="#inner-text"),
|
89 |
+
hx_get="/curated",
|
90 |
+
hx_target="#inner-text",
|
91 |
+
),
|
92 |
+
Div(
|
93 |
+
A("Common Steps", href="#inner-text"),
|
94 |
+
hx_get="/common",
|
95 |
+
hx_target="#inner-text",
|
96 |
+
),
|
97 |
+
Div(
|
98 |
+
A("TxT360 Results", href="#inner-text"),
|
99 |
+
hx_get="/results",
|
100 |
hx_target="#inner-text",
|
101 |
),
|
|
|
|
|
|
|
102 |
role="navigation",
|
103 |
cls="l-text figcaption",
|
104 |
),
|
|
|
252 |
)
|
253 |
|
254 |
|
255 |
+
@app.get("/webdata")
|
256 |
def web_data():
|
257 |
return Div(Section(H2(P("Web Data")), id="inner-text"))
|
258 |
|
259 |
|
260 |
+
def get_chart_28168342():
|
261 |
+
fig = go.Figure()
|
262 |
+
filter_names = [
|
263 |
+
"Download",
|
264 |
+
"Language",
|
265 |
+
"Min word count",
|
266 |
+
"Title Abstract",
|
267 |
+
"Majority language",
|
268 |
+
"Paragraph count",
|
269 |
+
"Frequency",
|
270 |
+
"Unigram log probability",
|
271 |
+
"Local dedup",
|
272 |
+
]
|
273 |
+
|
274 |
+
data_sources = [
|
275 |
+
("Wikipedia", [100, 90, 80, 70, 60, 50, 40, 30, 20]),
|
276 |
+
("Freelaw", [100, 90, 80, 70, 60, 50, 40, 20, 20]),
|
277 |
+
("DM Maths", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
278 |
+
("USPTO", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
279 |
+
("PG19", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
280 |
+
("Hackernews", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
281 |
+
("Ubuntu IRC", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
282 |
+
("Europarl", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
283 |
+
("StackExchange", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
284 |
+
("Arxiv", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
285 |
+
("S2ORC", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
286 |
+
("S2ORC Abstract", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
287 |
+
("PubMed Central", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
288 |
+
("PubMed Central Abstract", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
289 |
+
("PhilPapers", [100, 90, 80, 70, 60, 40, 40, 30, 20]),
|
290 |
+
]
|
291 |
+
|
292 |
+
for name, x_values in data_sources:
|
293 |
+
fig.add_trace(
|
294 |
+
go.Funnel(
|
295 |
+
name=name,
|
296 |
+
orientation="h",
|
297 |
+
y=filter_names,
|
298 |
+
x=x_values,
|
299 |
+
textinfo="value+percent total",
|
300 |
+
textposition="inside",
|
301 |
+
)
|
302 |
+
)
|
303 |
+
|
304 |
+
# Serialize the Plotly figure to JSON
|
305 |
+
fig_json = fig.to_json()
|
306 |
+
return fig
|
307 |
+
|
308 |
+
|
309 |
+
@app.get("/curated")
|
310 |
+
def curated():
|
311 |
+
return Div(plotly2fasthtml(get_chart_28168342()), id="inner-text")
|
312 |
+
|
313 |
+
|
314 |
+
@app.get("/common")
|
315 |
+
def common_steps():
|
316 |
+
return Div(Section(H2(P("Common Steps")), id="inner-text"))
|
317 |
+
|
318 |
+
|
319 |
+
@app.get("/results")
|
320 |
+
def results():
|
321 |
+
return Div(Section(H2(P("Results")), id="inner-text"))
|
322 |
+
|
323 |
+
|
324 |
serve()
|
style.css
CHANGED
@@ -63,6 +63,7 @@
|
|
63 |
gap: 10px;
|
64 |
}
|
65 |
|
|
|
66 |
.plotly_slider > input[type="range"] {
|
67 |
-webkit-appearance: none;
|
68 |
height: 2px;
|
@@ -138,6 +139,7 @@ d-byline .byline {
|
|
138 |
line-height: 1.8em;
|
139 |
}
|
140 |
|
|
|
141 |
@media (min-width: 768px) {
|
142 |
d-byline .byline {
|
143 |
grid-template-columns: 5fr 1fr 1fr;
|
@@ -173,10 +175,11 @@ d-contents a:hover {
|
|
173 |
}
|
174 |
|
175 |
|
176 |
-
@media (min-width:
|
177 |
d-article {
|
178 |
/* Ensure d-article does not prevent sticky positioning */
|
179 |
-
overflow-x: visible
|
|
|
180 |
}
|
181 |
|
182 |
d-contents {
|
|
|
63 |
gap: 10px;
|
64 |
}
|
65 |
|
66 |
+
|
67 |
.plotly_slider > input[type="range"] {
|
68 |
-webkit-appearance: none;
|
69 |
height: 2px;
|
|
|
139 |
line-height: 1.8em;
|
140 |
}
|
141 |
|
142 |
+
|
143 |
@media (min-width: 768px) {
|
144 |
d-byline .byline {
|
145 |
grid-template-columns: 5fr 1fr 1fr;
|
|
|
175 |
}
|
176 |
|
177 |
|
178 |
+
@media (min-width: 1100px) {
|
179 |
d-article {
|
180 |
/* Ensure d-article does not prevent sticky positioning */
|
181 |
+
overflow-x: visible;
|
182 |
+
grid-template-columns: [page-start] 1fr [page-start kicker-start] 1fr [middle-start] 1fr [text-start kicker-end] 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr [text-end gutter-start] 1fr [middle-end] 0fr [page-end gutter-end] 1fr [screen-end];
|
183 |
}
|
184 |
|
185 |
d-contents {
|