Update app.py
Browse files
app.py
CHANGED
@@ -124,70 +124,250 @@ def convert_messages_to_tuples(history: List[Dict[str, str]]) -> List[Tuple[str,
|
|
124 |
def create_ui() -> gr.Blocks:
|
125 |
"""Creates and configures the entire Gradio interface."""
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
# --- State Management ---
|
130 |
# Using simple, separate state objects for robustness.
|
131 |
repo_ids_state = gr.State([])
|
132 |
current_repo_idx_state = gr.State(0)
|
133 |
|
134 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
with gr.Tabs() as tabs:
|
137 |
# --- Input Tab ---
|
138 |
-
with gr.TabItem("
|
139 |
-
with gr.Row():
|
140 |
-
with gr.Column():
|
141 |
-
gr.Markdown("
|
142 |
repo_id_input = gr.Textbox(
|
143 |
-
label="
|
144 |
lines=8,
|
145 |
-
placeholder="
|
|
|
146 |
)
|
147 |
-
submit_repo_btn = gr.Button("Submit
|
148 |
-
|
149 |
-
|
|
|
150 |
keyword_input = gr.Textbox(
|
151 |
-
label="
|
152 |
lines=8,
|
153 |
-
placeholder="
|
|
|
154 |
)
|
155 |
-
search_btn = gr.Button("Search
|
156 |
|
157 |
-
status_box_input = gr.Textbox(label="Status", interactive=False)
|
158 |
|
159 |
# --- Analysis Tab ---
|
160 |
-
with gr.TabItem("
|
161 |
-
gr.Markdown("
|
162 |
-
analyze_next_btn = gr.Button("Analyze Next Repository", variant="primary")
|
163 |
-
status_box_analysis = gr.Textbox(label="Status", interactive=False)
|
164 |
|
165 |
with gr.Row():
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
-
gr.Markdown("###
|
170 |
-
df_output = gr.Dataframe(
|
|
|
|
|
|
|
|
|
171 |
|
172 |
# --- Chatbot Tab ---
|
173 |
-
with gr.TabItem("
|
174 |
-
gr.Markdown("
|
|
|
175 |
chatbot = gr.Chatbot(
|
176 |
value=[{"role": "assistant", "content": CHATBOT_INITIAL_MESSAGE}],
|
177 |
-
label="
|
178 |
-
height=
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
180 |
)
|
181 |
-
msg_input = gr.Textbox(label="Your Message", placeholder="Type your message here...", lines=2)
|
182 |
-
with gr.Row():
|
183 |
-
send_btn = gr.Button("Send", variant="primary")
|
184 |
-
end_chat_btn = gr.Button("End Chat & Get Keywords")
|
185 |
|
186 |
-
gr.
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
# --- Event Handler Functions ---
|
192 |
|
193 |
def handle_repo_id_submission(text: str) -> Tuple[List[str], int, pd.DataFrame, str, Any]:
|
|
|
124 |
def create_ui() -> gr.Blocks:
|
125 |
"""Creates and configures the entire Gradio interface."""
|
126 |
|
127 |
+
css = """
|
128 |
+
/* Modern sleek design */
|
129 |
+
.gradio-container {
|
130 |
+
font-family: 'Inter', 'system-ui', sans-serif;
|
131 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
132 |
+
min-height: 100vh;
|
133 |
+
}
|
134 |
+
|
135 |
+
.gr-form {
|
136 |
+
background: rgba(255, 255, 255, 0.95);
|
137 |
+
backdrop-filter: blur(10px);
|
138 |
+
border-radius: 16px;
|
139 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
140 |
+
padding: 24px;
|
141 |
+
margin: 16px;
|
142 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
143 |
+
}
|
144 |
+
|
145 |
+
.gr-button {
|
146 |
+
background: linear-gradient(45deg, #667eea, #764ba2);
|
147 |
+
border: none;
|
148 |
+
border-radius: 12px;
|
149 |
+
color: white;
|
150 |
+
font-weight: 600;
|
151 |
+
padding: 12px 24px;
|
152 |
+
transition: all 0.3s ease;
|
153 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
154 |
+
}
|
155 |
+
|
156 |
+
.gr-button:hover {
|
157 |
+
transform: translateY(-2px);
|
158 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
|
159 |
+
}
|
160 |
+
|
161 |
+
.gr-textbox {
|
162 |
+
border: 2px solid rgba(102, 126, 234, 0.2);
|
163 |
+
border-radius: 12px;
|
164 |
+
background: rgba(255, 255, 255, 0.9);
|
165 |
+
transition: all 0.3s ease;
|
166 |
+
}
|
167 |
+
|
168 |
+
.gr-textbox:focus {
|
169 |
+
border-color: #667eea;
|
170 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
171 |
+
}
|
172 |
+
|
173 |
+
.gr-panel {
|
174 |
+
background: rgba(255, 255, 255, 0.95);
|
175 |
+
border-radius: 16px;
|
176 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
177 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
178 |
+
}
|
179 |
+
|
180 |
+
.gr-tab-nav {
|
181 |
+
background: rgba(255, 255, 255, 0.95);
|
182 |
+
border-radius: 12px 12px 0 0;
|
183 |
+
backdrop-filter: blur(10px);
|
184 |
+
}
|
185 |
+
|
186 |
+
.gr-tab-nav button {
|
187 |
+
background: transparent;
|
188 |
+
border: none;
|
189 |
+
padding: 16px 24px;
|
190 |
+
font-weight: 600;
|
191 |
+
color: #666;
|
192 |
+
transition: all 0.3s ease;
|
193 |
+
}
|
194 |
+
|
195 |
+
.gr-tab-nav button.selected {
|
196 |
+
background: linear-gradient(45deg, #667eea, #764ba2);
|
197 |
+
color: white;
|
198 |
+
border-radius: 8px;
|
199 |
+
}
|
200 |
+
|
201 |
+
.chatbot {
|
202 |
+
border-radius: 16px;
|
203 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
204 |
+
}
|
205 |
+
|
206 |
+
/* Hide Gradio footer */
|
207 |
+
footer {
|
208 |
+
display: none !important;
|
209 |
+
}
|
210 |
+
|
211 |
+
/* Custom scrollbar */
|
212 |
+
::-webkit-scrollbar {
|
213 |
+
width: 8px;
|
214 |
+
}
|
215 |
+
|
216 |
+
::-webkit-scrollbar-track {
|
217 |
+
background: rgba(255, 255, 255, 0.1);
|
218 |
+
border-radius: 4px;
|
219 |
+
}
|
220 |
+
|
221 |
+
::-webkit-scrollbar-thumb {
|
222 |
+
background: linear-gradient(45deg, #667eea, #764ba2);
|
223 |
+
border-radius: 4px;
|
224 |
+
}
|
225 |
+
"""
|
226 |
+
|
227 |
+
with gr.Blocks(
|
228 |
+
theme=gr.themes.Soft(
|
229 |
+
primary_hue="blue",
|
230 |
+
secondary_hue="purple",
|
231 |
+
neutral_hue="gray",
|
232 |
+
font=["Inter", "system-ui", "sans-serif"]
|
233 |
+
),
|
234 |
+
css=css,
|
235 |
+
title="π HF Repo Analyzer"
|
236 |
+
) as app:
|
237 |
|
238 |
# --- State Management ---
|
239 |
# Using simple, separate state objects for robustness.
|
240 |
repo_ids_state = gr.State([])
|
241 |
current_repo_idx_state = gr.State(0)
|
242 |
|
243 |
+
gr.Markdown(
|
244 |
+
"""
|
245 |
+
<div style="text-align: center; padding: 40px 20px; background: rgba(255, 255, 255, 0.1); border-radius: 20px; margin: 20px auto; max-width: 900px; backdrop-filter: blur(10px);">
|
246 |
+
<h1 style="font-size: 3.5rem; font-weight: 800; margin: 0; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;">
|
247 |
+
π HF Repo Analyzer
|
248 |
+
</h1>
|
249 |
+
<p style="font-size: 1.3rem; color: rgba(255, 255, 255, 0.9); margin: 16px 0 0 0; font-weight: 400; line-height: 1.6;">
|
250 |
+
Discover, analyze, and evaluate Hugging Face repositories with AI-powered insights
|
251 |
+
</p>
|
252 |
+
<div style="height: 4px; width: 80px; background: linear-gradient(45deg, #667eea, #764ba2); margin: 24px auto; border-radius: 2px;"></div>
|
253 |
+
</div>
|
254 |
+
"""
|
255 |
+
)
|
256 |
|
257 |
with gr.Tabs() as tabs:
|
258 |
# --- Input Tab ---
|
259 |
+
with gr.TabItem("π Input & Search", id="input_tab"):
|
260 |
+
with gr.Row(equal_height=True):
|
261 |
+
with gr.Column(scale=1):
|
262 |
+
gr.Markdown("### π Repository IDs")
|
263 |
repo_id_input = gr.Textbox(
|
264 |
+
label="Repository IDs",
|
265 |
lines=8,
|
266 |
+
placeholder="microsoft/DialoGPT-medium\nopenai/whisper\nhuggingface/transformers",
|
267 |
+
info="Enter repo IDs separated by commas or new lines"
|
268 |
)
|
269 |
+
submit_repo_btn = gr.Button("π Submit Repositories", variant="primary", size="lg")
|
270 |
+
|
271 |
+
with gr.Column(scale=1):
|
272 |
+
gr.Markdown("### π Keyword Search")
|
273 |
keyword_input = gr.Textbox(
|
274 |
+
label="Search Keywords",
|
275 |
lines=8,
|
276 |
+
placeholder="text generation\nimage classification\nsentiment analysis",
|
277 |
+
info="Enter keywords to find relevant repositories"
|
278 |
)
|
279 |
+
search_btn = gr.Button("π Search Repositories", variant="primary", size="lg")
|
280 |
|
281 |
+
status_box_input = gr.Textbox(label="π Status", interactive=False, lines=2)
|
282 |
|
283 |
# --- Analysis Tab ---
|
284 |
+
with gr.TabItem("π¬ Analysis", id="analysis_tab"):
|
285 |
+
gr.Markdown("### π§ͺ Repository Analysis Engine")
|
|
|
|
|
286 |
|
287 |
with gr.Row():
|
288 |
+
analyze_next_btn = gr.Button("β‘ Analyze Next Repository", variant="primary", size="lg", scale=2)
|
289 |
+
with gr.Column(scale=3):
|
290 |
+
status_box_analysis = gr.Textbox(label="π Analysis Status", interactive=False, lines=2)
|
291 |
+
|
292 |
+
with gr.Row(equal_height=True):
|
293 |
+
with gr.Column():
|
294 |
+
content_output = gr.Textbox(
|
295 |
+
label="π Repository Content",
|
296 |
+
lines=20,
|
297 |
+
show_copy_button=True,
|
298 |
+
info="Raw content extracted from the repository"
|
299 |
+
)
|
300 |
+
with gr.Column():
|
301 |
+
summary_output = gr.Textbox(
|
302 |
+
label="π― AI Analysis Summary",
|
303 |
+
lines=20,
|
304 |
+
show_copy_button=True,
|
305 |
+
info="Detailed analysis and insights from AI"
|
306 |
+
)
|
307 |
|
308 |
+
gr.Markdown("### π Results Dashboard")
|
309 |
+
df_output = gr.Dataframe(
|
310 |
+
headers=["Repository", "Strengths", "Weaknesses", "Speciality", "Relevance"],
|
311 |
+
wrap=True,
|
312 |
+
interactive=False
|
313 |
+
)
|
314 |
|
315 |
# --- Chatbot Tab ---
|
316 |
+
with gr.TabItem("π€ AI Assistant", id="chatbot_tab"):
|
317 |
+
gr.Markdown("### π¬ Intelligent Repository Discovery")
|
318 |
+
|
319 |
chatbot = gr.Chatbot(
|
320 |
value=[{"role": "assistant", "content": CHATBOT_INITIAL_MESSAGE}],
|
321 |
+
label="π€ AI Assistant",
|
322 |
+
height=450,
|
323 |
+
bubble_full_width=False,
|
324 |
+
avatar_images=(
|
325 |
+
"https://cdn-icons-png.flaticon.com/512/149/149071.png",
|
326 |
+
"https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png"
|
327 |
+
),
|
328 |
+
show_copy_button=True
|
329 |
)
|
|
|
|
|
|
|
|
|
330 |
|
331 |
+
with gr.Row():
|
332 |
+
msg_input = gr.Textbox(
|
333 |
+
label="π Your Message",
|
334 |
+
placeholder="Tell me about your ideal repository...",
|
335 |
+
lines=1,
|
336 |
+
scale=4,
|
337 |
+
info="Describe what you're looking for"
|
338 |
+
)
|
339 |
+
send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
340 |
+
end_chat_btn = gr.Button("π― Extract Keywords", scale=1)
|
341 |
+
use_keywords_btn = gr.Button("π Search Now", variant="primary", scale=1)
|
342 |
+
|
343 |
+
with gr.Row():
|
344 |
+
with gr.Column():
|
345 |
+
extracted_keywords_output = gr.Textbox(
|
346 |
+
label="π·οΈ Extracted Keywords",
|
347 |
+
interactive=False,
|
348 |
+
show_copy_button=True,
|
349 |
+
info="AI-generated search terms from our conversation"
|
350 |
+
)
|
351 |
+
with gr.Column():
|
352 |
+
status_box_chatbot = gr.Textbox(
|
353 |
+
label="π Chat Status",
|
354 |
+
interactive=False,
|
355 |
+
info="Current conversation status"
|
356 |
+
)
|
357 |
|
358 |
+
# --- Footer ---
|
359 |
+
gr.Markdown(
|
360 |
+
"""
|
361 |
+
<div style="text-align: center; padding: 30px 20px; margin-top: 40px; background: rgba(255, 255, 255, 0.1); border-radius: 16px; backdrop-filter: blur(10px);">
|
362 |
+
<p style="margin: 0; color: rgba(255, 255, 255, 0.8); font-size: 0.95rem; font-weight: 500;">
|
363 |
+
π Powered by <span style="background: linear-gradient(45deg, #667eea, #764ba2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 700;">Gradio</span>
|
364 |
+
& <span style="background: linear-gradient(45deg, #667eea, #764ba2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 700;">Hugging Face</span>
|
365 |
+
</p>
|
366 |
+
<div style="height: 2px; width: 60px; background: linear-gradient(45deg, #667eea, #764ba2); margin: 16px auto; border-radius: 1px;"></div>
|
367 |
+
</div>
|
368 |
+
"""
|
369 |
+
)
|
370 |
+
|
371 |
# --- Event Handler Functions ---
|
372 |
|
373 |
def handle_repo_id_submission(text: str) -> Tuple[List[str], int, pd.DataFrame, str, Any]:
|