m7n commited on
Commit
fc74e8d
·
verified ·
1 Parent(s): 985ef3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -10
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
- with open(file_path, "w") as f:
42
- f.write(f"""
43
- <script src="https://cdn.tailwindcss.com"></script>
44
- <body class="bg-gray-200 dark:text-white dark:bg-gray-900">
45
- <h1 class="text-3xl font-bold">
46
- Hello <i>{text_input}</i> From Gradio Iframe
47
- </h1>
48
- <h3>Filename: {file_name}</h3>
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