Spaces:
Sleeping
Sleeping
- app.py +68 -4
- repo_explorer.py +50 -52
app.py
CHANGED
|
@@ -39,10 +39,37 @@ def write_repos_to_csv(repo_ids: List[str]) -> None:
|
|
| 39 |
except Exception as e:
|
| 40 |
logger.error(f"Error writing to CSV: {e}")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def read_csv_to_dataframe() -> pd.DataFrame:
|
| 43 |
-
"""Reads the CSV file into a pandas DataFrame."""
|
| 44 |
try:
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except FileNotFoundError:
|
| 47 |
return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
|
| 48 |
except Exception as e:
|
|
@@ -225,6 +252,38 @@ def create_ui() -> gr.Blocks:
|
|
| 225 |
background: linear-gradient(45deg, #667eea, #764ba2);
|
| 226 |
border-radius: 4px;
|
| 227 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
"""
|
| 229 |
|
| 230 |
with gr.Blocks(
|
|
@@ -324,7 +383,11 @@ def create_ui() -> gr.Blocks:
|
|
| 324 |
df_output = gr.Dataframe(
|
| 325 |
headers=["Repository", "Strengths", "Weaknesses", "Speciality", "Relevance"],
|
| 326 |
wrap=True,
|
| 327 |
-
interactive=False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
)
|
| 329 |
|
| 330 |
# --- Chatbot Tab ---
|
|
@@ -370,7 +433,8 @@ def create_ui() -> gr.Blocks:
|
|
| 370 |
)
|
| 371 |
|
| 372 |
# --- Repo Explorer Tab ---
|
| 373 |
-
|
|
|
|
| 374 |
|
| 375 |
# --- Footer ---
|
| 376 |
gr.Markdown(
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
logger.error(f"Error writing to CSV: {e}")
|
| 41 |
|
| 42 |
+
def format_text_for_dataframe(text: str, max_length: int = 200) -> str:
|
| 43 |
+
"""Format text for better display in dataframe by truncating and cleaning."""
|
| 44 |
+
if not text or pd.isna(text):
|
| 45 |
+
return ""
|
| 46 |
+
|
| 47 |
+
# Clean the text
|
| 48 |
+
text = str(text).strip()
|
| 49 |
+
|
| 50 |
+
# Remove excessive whitespace and newlines
|
| 51 |
+
text = re.sub(r'\s+', ' ', text)
|
| 52 |
+
|
| 53 |
+
# Truncate if too long
|
| 54 |
+
if len(text) > max_length:
|
| 55 |
+
text = text[:max_length-3] + "..."
|
| 56 |
+
|
| 57 |
+
return text
|
| 58 |
+
|
| 59 |
def read_csv_to_dataframe() -> pd.DataFrame:
|
| 60 |
+
"""Reads the CSV file into a pandas DataFrame with formatted text for display."""
|
| 61 |
try:
|
| 62 |
+
df = pd.read_csv(CSV_FILE, dtype=str).fillna('')
|
| 63 |
+
|
| 64 |
+
# Format text columns for better display
|
| 65 |
+
if not df.empty:
|
| 66 |
+
df['strength'] = df['strength'].apply(lambda x: format_text_for_dataframe(x, 180))
|
| 67 |
+
df['weaknesses'] = df['weaknesses'].apply(lambda x: format_text_for_dataframe(x, 180))
|
| 68 |
+
df['speciality'] = df['speciality'].apply(lambda x: format_text_for_dataframe(x, 150))
|
| 69 |
+
df['repo id'] = df['repo id'].apply(lambda x: format_text_for_dataframe(x, 50))
|
| 70 |
+
# Keep relevance rating as is since it should be short
|
| 71 |
+
|
| 72 |
+
return df
|
| 73 |
except FileNotFoundError:
|
| 74 |
return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
|
| 75 |
except Exception as e:
|
|
|
|
| 252 |
background: linear-gradient(45deg, #667eea, #764ba2);
|
| 253 |
border-radius: 4px;
|
| 254 |
}
|
| 255 |
+
|
| 256 |
+
/* Improved dataframe styling */
|
| 257 |
+
.gr-dataframe {
|
| 258 |
+
max-height: 400px;
|
| 259 |
+
overflow-y: auto;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
.gr-dataframe table {
|
| 263 |
+
table-layout: fixed;
|
| 264 |
+
width: 100%;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.gr-dataframe th,
|
| 268 |
+
.gr-dataframe td {
|
| 269 |
+
padding: 8px 12px;
|
| 270 |
+
vertical-align: top;
|
| 271 |
+
word-wrap: break-word;
|
| 272 |
+
overflow-wrap: break-word;
|
| 273 |
+
max-height: 100px;
|
| 274 |
+
overflow-y: auto;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
.gr-dataframe th:nth-child(1),
|
| 278 |
+
.gr-dataframe td:nth-child(1) { width: 15%; }
|
| 279 |
+
.gr-dataframe th:nth-child(2),
|
| 280 |
+
.gr-dataframe td:nth-child(2) { width: 25%; }
|
| 281 |
+
.gr-dataframe th:nth-child(3),
|
| 282 |
+
.gr-dataframe td:nth-child(3) { width: 25%; }
|
| 283 |
+
.gr-dataframe th:nth-child(4),
|
| 284 |
+
.gr-dataframe td:nth-child(4) { width: 20%; }
|
| 285 |
+
.gr-dataframe th:nth-child(5),
|
| 286 |
+
.gr-dataframe td:nth-child(5) { width: 15%; }
|
| 287 |
"""
|
| 288 |
|
| 289 |
with gr.Blocks(
|
|
|
|
| 383 |
df_output = gr.Dataframe(
|
| 384 |
headers=["Repository", "Strengths", "Weaknesses", "Speciality", "Relevance"],
|
| 385 |
wrap=True,
|
| 386 |
+
interactive=False,
|
| 387 |
+
max_rows=10,
|
| 388 |
+
height=400,
|
| 389 |
+
column_widths=["15%", "25%", "25%", "20%", "15%"],
|
| 390 |
+
datatype=["str", "str", "str", "str", "str"]
|
| 391 |
)
|
| 392 |
|
| 393 |
# --- Chatbot Tab ---
|
|
|
|
| 433 |
)
|
| 434 |
|
| 435 |
# --- Repo Explorer Tab ---
|
| 436 |
+
with gr.TabItem("π Repo Explorer", id="repo_explorer_tab"):
|
| 437 |
+
repo_components, repo_states = create_repo_explorer_tab()
|
| 438 |
|
| 439 |
# --- Footer ---
|
| 440 |
gr.Markdown(
|
repo_explorer.py
CHANGED
|
@@ -120,10 +120,9 @@ Make this comprehensive but conversational - it will be used by a chatbot to ans
|
|
| 120 |
logger.error(f"Error creating repo context summary: {e}")
|
| 121 |
return f"Repository analysis unavailable: {e}"
|
| 122 |
|
| 123 |
-
def create_repo_explorer_tab() -> Tuple[
|
| 124 |
"""
|
| 125 |
-
Creates the Repo Explorer tab
|
| 126 |
-
component references, and state variables.
|
| 127 |
"""
|
| 128 |
|
| 129 |
# State variables for repo explorer
|
|
@@ -132,58 +131,57 @@ def create_repo_explorer_tab() -> Tuple[gr.TabItem, Dict[str, gr.components.Comp
|
|
| 132 |
"current_repo_id": gr.State("")
|
| 133 |
}
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
with gr.
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
)
|
| 145 |
-
|
| 146 |
-
load_repo_btn = gr.Button("π Load Repository", variant="primary", size="lg")
|
| 147 |
|
| 148 |
-
with gr.
|
| 149 |
-
|
| 150 |
-
label="
|
|
|
|
| 151 |
interactive=False,
|
| 152 |
-
|
| 153 |
-
info="
|
| 154 |
)
|
| 155 |
-
|
| 156 |
-
with gr.Row():
|
| 157 |
-
with gr.Column(scale=2):
|
| 158 |
-
repo_chatbot = gr.Chatbot(
|
| 159 |
-
label="π€ Repository Assistant",
|
| 160 |
-
height=500,
|
| 161 |
-
type="messages",
|
| 162 |
-
avatar_images=(
|
| 163 |
-
"https://cdn-icons-png.flaticon.com/512/149/149071.png",
|
| 164 |
-
"https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png"
|
| 165 |
-
),
|
| 166 |
-
show_copy_button=True
|
| 167 |
-
)
|
| 168 |
-
|
| 169 |
-
with gr.Row():
|
| 170 |
-
repo_msg_input = gr.Textbox(
|
| 171 |
-
label="π Ask about this repository",
|
| 172 |
-
placeholder="What does this repository do? How do I use it?",
|
| 173 |
-
lines=1,
|
| 174 |
-
scale=4,
|
| 175 |
-
info="Ask anything about the loaded repository"
|
| 176 |
-
)
|
| 177 |
-
repo_send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
| 178 |
-
|
| 179 |
-
with gr.Column(scale=1):
|
| 180 |
-
repo_content_display = gr.Textbox(
|
| 181 |
-
label="π Repository Content Preview",
|
| 182 |
-
lines=25,
|
| 183 |
-
interactive=False,
|
| 184 |
-
show_copy_button=True,
|
| 185 |
-
info="Preview of the repository files and content"
|
| 186 |
-
)
|
| 187 |
|
| 188 |
# Component references
|
| 189 |
components = {
|
|
@@ -196,7 +194,7 @@ def create_repo_explorer_tab() -> Tuple[gr.TabItem, Dict[str, gr.components.Comp
|
|
| 196 |
"repo_content_display": repo_content_display
|
| 197 |
}
|
| 198 |
|
| 199 |
-
return
|
| 200 |
|
| 201 |
def handle_load_repository(repo_id: str) -> Tuple[str, str, str]:
|
| 202 |
"""Load a specific repository and prepare it for exploration with chunk-based analysis."""
|
|
|
|
| 120 |
logger.error(f"Error creating repo context summary: {e}")
|
| 121 |
return f"Repository analysis unavailable: {e}"
|
| 122 |
|
| 123 |
+
def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict[str, gr.State]]:
|
| 124 |
"""
|
| 125 |
+
Creates the Repo Explorer tab content and returns the component references and state variables.
|
|
|
|
| 126 |
"""
|
| 127 |
|
| 128 |
# State variables for repo explorer
|
|
|
|
| 131 |
"current_repo_id": gr.State("")
|
| 132 |
}
|
| 133 |
|
| 134 |
+
gr.Markdown("### ποΈ Deep Dive into a Specific Repository")
|
| 135 |
+
|
| 136 |
+
with gr.Row():
|
| 137 |
+
with gr.Column(scale=2):
|
| 138 |
+
repo_explorer_input = gr.Textbox(
|
| 139 |
+
label="π Repository ID",
|
| 140 |
+
placeholder="microsoft/DialoGPT-medium",
|
| 141 |
+
info="Enter a Hugging Face repository ID to explore"
|
| 142 |
+
)
|
| 143 |
+
with gr.Column(scale=1):
|
| 144 |
+
load_repo_btn = gr.Button("π Load Repository", variant="primary", size="lg")
|
| 145 |
+
|
| 146 |
+
with gr.Row():
|
| 147 |
+
repo_status_display = gr.Textbox(
|
| 148 |
+
label="π Repository Status",
|
| 149 |
+
interactive=False,
|
| 150 |
+
lines=3,
|
| 151 |
+
info="Current repository loading status and basic info"
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
with gr.Row():
|
| 155 |
+
with gr.Column(scale=2):
|
| 156 |
+
repo_chatbot = gr.Chatbot(
|
| 157 |
+
label="π€ Repository Assistant",
|
| 158 |
+
height=500,
|
| 159 |
+
type="messages",
|
| 160 |
+
avatar_images=(
|
| 161 |
+
"https://cdn-icons-png.flaticon.com/512/149/149071.png",
|
| 162 |
+
"https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png"
|
| 163 |
+
),
|
| 164 |
+
show_copy_button=True
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
with gr.Row():
|
| 168 |
+
repo_msg_input = gr.Textbox(
|
| 169 |
+
label="π Ask about this repository",
|
| 170 |
+
placeholder="What does this repository do? How do I use it?",
|
| 171 |
+
lines=1,
|
| 172 |
+
scale=4,
|
| 173 |
+
info="Ask anything about the loaded repository"
|
| 174 |
)
|
| 175 |
+
repo_send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
|
|
|
| 176 |
|
| 177 |
+
with gr.Column(scale=1):
|
| 178 |
+
repo_content_display = gr.Textbox(
|
| 179 |
+
label="π Repository Content Preview",
|
| 180 |
+
lines=25,
|
| 181 |
interactive=False,
|
| 182 |
+
show_copy_button=True,
|
| 183 |
+
info="Preview of the repository files and content"
|
| 184 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
# Component references
|
| 187 |
components = {
|
|
|
|
| 194 |
"repo_content_display": repo_content_display
|
| 195 |
}
|
| 196 |
|
| 197 |
+
return components, states
|
| 198 |
|
| 199 |
def handle_load_repository(repo_id: str) -> Tuple[str, str, str]:
|
| 200 |
"""Load a specific repository and prepare it for exploration with chunk-based analysis."""
|