lambdaofgod
commited on
Commit
•
3c48254
1
Parent(s):
2b00dd6
repo representation visualization
Browse files- data/repo_representations.jsonl +0 -0
- display_representations.py +105 -0
- requirements.txt +1 -0
data/repo_representations.jsonl
ADDED
The diff for this file is too large to render.
See raw diff
|
|
display_representations.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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 |
+
def load_repo_df(data_path="data/repo_representations.jsonl"):
|
11 |
+
data = pd.read_json(data_path, lines=True, orient="records")
|
12 |
+
return data.assign(
|
13 |
+
text=data["text"]
|
14 |
+
.str.replace(r"<img.*\/>", "", regex=True)
|
15 |
+
.str.replace("│", "\n")
|
16 |
+
.str.replace("⋮", "\n")
|
17 |
+
)
|
18 |
+
|
19 |
+
|
20 |
+
def display_representations(repo, representation1, representation2):
|
21 |
+
repo_data = repos_df[repos_df["repo_name"] == repo]
|
22 |
+
logging.info(f"repo_data: {repo_data}")
|
23 |
+
text1 = (
|
24 |
+
repo_data[repo_data["representation"] == representation1]["text"].iloc[0]
|
25 |
+
if not repo_data[repo_data["representation"] == representation1].empty
|
26 |
+
else "No data available"
|
27 |
+
)
|
28 |
+
text2 = (
|
29 |
+
repo_data[repo_data["representation"] == representation2]["text"].iloc[0]
|
30 |
+
if not repo_data[repo_data["representation"] == representation2].empty
|
31 |
+
else "No data available"
|
32 |
+
)
|
33 |
+
|
34 |
+
return text1, text2
|
35 |
+
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
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():
|
49 |
+
repo = gr.Dropdown(choices=repos, label="Repository", value=repos[0])
|
50 |
+
representation1 = gr.Dropdown(
|
51 |
+
choices=representation_types, label="Representation 1", value="readme"
|
52 |
+
)
|
53 |
+
representation2 = gr.Dropdown(
|
54 |
+
choices=representation_types,
|
55 |
+
label="Representation 2",
|
56 |
+
value="generated_readme",
|
57 |
+
)
|
58 |
+
|
59 |
+
with gr.Row():
|
60 |
+
with gr.Box(elem_id="box1"):
|
61 |
+
text1 = gr.Markdown()
|
62 |
+
with gr.Box(elem_id="box2"):
|
63 |
+
text2 = gr.Markdown()
|
64 |
+
|
65 |
+
# Add custom CSS
|
66 |
+
gr.Markdown(
|
67 |
+
"""
|
68 |
+
<style>
|
69 |
+
#box1, #box2 {
|
70 |
+
border: 2px solid #ddd;
|
71 |
+
border-radius: 10px;
|
72 |
+
padding: 10px;
|
73 |
+
margin: 10px;
|
74 |
+
background-color: #f9f9f9;
|
75 |
+
}
|
76 |
+
#box1 {
|
77 |
+
border-color: #007bff;
|
78 |
+
}
|
79 |
+
#box2 {
|
80 |
+
border-color: #28a745;
|
81 |
+
}
|
82 |
+
</style>
|
83 |
+
"""
|
84 |
+
)
|
85 |
+
|
86 |
+
def update_representations(*args):
|
87 |
+
text1_content, text2_content = display_representations(*args)
|
88 |
+
return (
|
89 |
+
f"### Representation 1\n\n{text1_content}",
|
90 |
+
f"### Representation 2\n\n{text2_content}",
|
91 |
+
)
|
92 |
+
|
93 |
+
# Initial call to populate textboxes with default values
|
94 |
+
text1.value, text2.value = update_representations(
|
95 |
+
repos[0], "readme", "generated_readme"
|
96 |
+
)
|
97 |
+
|
98 |
+
for component in [repo, representation1, representation2]:
|
99 |
+
component.change(
|
100 |
+
fn=update_representations,
|
101 |
+
inputs=[repo, representation1, representation2],
|
102 |
+
outputs=[text1, text2],
|
103 |
+
)
|
104 |
+
|
105 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio==3.48.0
|