Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -34,24 +34,46 @@ app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
|
34 |
# Gradio stuff
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def predict(text_input):
|
38 |
file_name = f"{datetime.utcnow().strftime('%s')}.html"
|
39 |
file_path = static_dir / file_name
|
40 |
print(file_path)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
iframe = f"""<iframe src="/static/{file_name}" width="100%" height="500px"></iframe>"""
|
51 |
link = f'<a href="/static/{file_name}" target="_blank">{file_name}</a>'
|
52 |
return link, iframe
|
53 |
|
54 |
-
|
55 |
with gr.Blocks() as block:
|
56 |
gr.Markdown("""
|
57 |
## Gradio + FastAPI + Static Server
|
|
|
34 |
# Gradio stuff
|
35 |
|
36 |
|
37 |
+
|
38 |
+
import datamapplot
|
39 |
+
import numpy as np
|
40 |
+
import requests
|
41 |
+
import io
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
def predict(text_input):
|
46 |
file_name = f"{datetime.utcnow().strftime('%s')}.html"
|
47 |
file_path = static_dir / file_name
|
48 |
print(file_path)
|
49 |
+
|
50 |
+
base_url = "https://github.com/TutteInstitute/datamapplot"
|
51 |
+
data_map_file = requests.get(
|
52 |
+
f"{base_url}/raw/main/examples/arxiv_ml_data_map.npy"
|
53 |
+
)
|
54 |
+
arxivml_data_map = np.load(io.BytesIO(data_map_file.content))
|
55 |
+
arxivml_label_layers = []
|
56 |
+
for layer_num in range(5):
|
57 |
+
label_file = requests.get(
|
58 |
+
f"{base_url}/raw/interactive/examples/arxiv_ml_layer{layer_num}_cluster_labels.npy"
|
59 |
+
)
|
60 |
+
arxivml_label_layers.append(np.load(io.BytesIO(label_file.content), allow_pickle=True))
|
61 |
+
|
62 |
+
plot = datamapplot.create_interactive_plot(
|
63 |
+
arxivml_data_map,
|
64 |
+
arxivml_label_layers[2],)
|
65 |
+
|
66 |
+
plot.save(file_path)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
iframe = f"""<iframe src="/static/{file_name}" width="100%" height="500px"></iframe>"""
|
74 |
link = f'<a href="/static/{file_name}" target="_blank">{file_name}</a>'
|
75 |
return link, iframe
|
76 |
|
|
|
77 |
with gr.Blocks() as block:
|
78 |
gr.Markdown("""
|
79 |
## Gradio + FastAPI + Static Server
|