Commit
·
1352e18
1
Parent(s):
39e83f7
feat: Add task visualizations tab to the Gradio app
Browse files
app.py
CHANGED
@@ -2,13 +2,20 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import logging
|
4 |
import re
|
5 |
-
|
6 |
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
return data.assign(
|
13 |
text=data["text"]
|
14 |
.str.replace(r"<img.*\/>", "", regex=True)
|
@@ -34,15 +41,7 @@ def display_representations(repo, representation1, representation2):
|
|
34 |
return text1, text2
|
35 |
|
36 |
|
37 |
-
|
38 |
-
repos_df = load_repo_df()
|
39 |
-
repos = list(repos_df["repo_name"].unique())
|
40 |
-
representation_types = list(repos_df["representation"].unique())
|
41 |
-
logging.info(f"found {len(repos)} repositories")
|
42 |
-
logging.info(f"representation types: {representation_types}")
|
43 |
-
|
44 |
-
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown("# Repository Representations Viewer")
|
46 |
gr.Markdown("Select a repository and two representation types to compare them.")
|
47 |
|
48 |
with gr.Row():
|
@@ -93,4 +92,25 @@ with gr.Blocks() as demo:
|
|
93 |
outputs=[text1, text2],
|
94 |
)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
demo.launch()
|
|
|
2 |
import pandas as pd
|
3 |
import logging
|
4 |
import re
|
5 |
+
from task_visualizations import TaskVisualizations
|
6 |
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
|
10 |
+
class AppConfig:
|
11 |
+
repo_representations_path = "data/repo_representations.jsonl"
|
12 |
+
task_counts_path = "data/repos_task_counts.csv"
|
13 |
+
selected_task_counts_path = "data/selected_repos_task_counts.csv"
|
14 |
+
tasks_path = "data/paperswithcode_tasks.csv"
|
15 |
+
|
16 |
+
|
17 |
+
def load_repo_df(repo_representations_path):
|
18 |
+
data = pd.read_json(repo_representations_path, lines=True, orient="records")
|
19 |
return data.assign(
|
20 |
text=data["text"]
|
21 |
.str.replace(r"<img.*\/>", "", regex=True)
|
|
|
41 |
return text1, text2
|
42 |
|
43 |
|
44 |
+
def setup_repository_representations_tab(repos, representation_types):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
gr.Markdown("Select a repository and two representation types to compare them.")
|
46 |
|
47 |
with gr.Row():
|
|
|
92 |
outputs=[text1, text2],
|
93 |
)
|
94 |
|
95 |
+
|
96 |
+
## main
|
97 |
+
repos_df = load_repo_df()
|
98 |
+
repos = list(repos_df["repo_name"].unique())
|
99 |
+
representation_types = list(repos_df["representation"].unique())
|
100 |
+
logging.info(f"found {len(repos)} repositories")
|
101 |
+
logging.info(f"representation types: {representation_types}")
|
102 |
+
task_visualizations = TaskVisualizations(
|
103 |
+
AppConfig.task_counts_path,
|
104 |
+
AppConfig.selected_task_counts_path,
|
105 |
+
AppConfig.tasks_path,
|
106 |
+
)
|
107 |
+
|
108 |
+
with gr.Blocks() as demo:
|
109 |
+
with gr.Tab("Explore Repository Representations"):
|
110 |
+
setup_repository_representations_tab(repos, representation_types)
|
111 |
+
with gr.Tab("Explore PapersWithCode Tasks"):
|
112 |
+
with open("plots/pwc_area_tasks_sunburst.html") as f:
|
113 |
+
sunburst_tasks = f.read()
|
114 |
+
gr.HTML(sunburst_tasks)
|
115 |
+
|
116 |
demo.launch()
|