Spaces:
Sleeping
Sleeping
message_init
Browse files- app.py +35 -13
- chatbot_page.py +7 -3
app.py
CHANGED
|
@@ -389,17 +389,24 @@ with gr.Blocks() as demo:
|
|
| 389 |
batch_btn = gr.Button("Batch Analyze All & Select Top 3", visible=True)
|
| 390 |
batch_info_txt = gr.Textbox(label="All Repo Analyses", lines=10)
|
| 391 |
top3_txt = gr.Textbox(label="Top 3 Repo IDs", lines=1)
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
# Navigation logic
|
| 395 |
-
option_a_btn.click(go_to_input, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 396 |
-
option_b_btn.click(go_to_chatbot, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 397 |
-
next_btn.click(go_to_analysis, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page])
|
| 398 |
-
back_btn.click(go_to_input, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page])
|
| 399 |
-
back_to_start_btn.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 400 |
-
back_to_start_btn2.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 401 |
-
back_to_start_btn3.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 402 |
-
back_to_start_btn4.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
|
|
|
| 403 |
|
| 404 |
# Keyword and repo input logic
|
| 405 |
keyword_btn.click(keyword_search_and_update, inputs=keyword_input, outputs=df_box)
|
|
@@ -424,20 +431,35 @@ with gr.Blocks() as demo:
|
|
| 424 |
def go_to_results_from_chatbot(keywords):
|
| 425 |
# Use the keywords to search and update the CSV, then display the DataFrame
|
| 426 |
df = use_keywords_to_search_and_update_csv(keywords)
|
| 427 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), df
|
| 428 |
|
| 429 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 430 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
| 431 |
go_to_results_btn.click(
|
| 432 |
go_to_results_from_chatbot,
|
| 433 |
inputs=keywords_output,
|
| 434 |
-
outputs=[chatbot_page, input_page, analysis_page, results_page, results_df]
|
| 435 |
)
|
| 436 |
|
| 437 |
# Add logic for the new button on results_page
|
| 438 |
analyze_next_btn.click(show_combined_repo_and_llm, inputs=None, outputs=[combined_txt_results, llm_output_txt_results, results_df])
|
| 439 |
-
# Batch analyze and show top 3 logic (now only on results page)
|
| 440 |
batch_btn.click(batch_analyze_and_select_top, inputs=None, outputs=[batch_info_txt, top3_txt, df_output])
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
demo.launch()
|
|
|
|
| 389 |
batch_btn = gr.Button("Batch Analyze All & Select Top 3", visible=True)
|
| 390 |
batch_info_txt = gr.Textbox(label="All Repo Analyses", lines=10)
|
| 391 |
top3_txt = gr.Textbox(label="Top 3 Repo IDs", lines=1)
|
| 392 |
+
show_top3_page_btn = gr.Button("Show Top 3 Repos on New Page", visible=True)
|
| 393 |
+
|
| 394 |
+
# --- Page 5: Top 3 Repos Page ---
|
| 395 |
+
with gr.Column(visible=False) as top3_page:
|
| 396 |
+
gr.Markdown("## Top 3 Recommended Repos")
|
| 397 |
+
top3_df = gr.Dataframe(headers=["repo id"], datatype=["str"])
|
| 398 |
+
back_to_results_btn = gr.Button("Back to Results")
|
| 399 |
|
| 400 |
# Navigation logic
|
| 401 |
+
option_a_btn.click(go_to_input, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 402 |
+
option_b_btn.click(go_to_chatbot, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 403 |
+
next_btn.click(go_to_analysis, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page, top3_page])
|
| 404 |
+
back_btn.click(go_to_input, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page, top3_page])
|
| 405 |
+
back_to_start_btn.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 406 |
+
back_to_start_btn2.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 407 |
+
back_to_start_btn3.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 408 |
+
back_to_start_btn4.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 409 |
+
back_to_results_btn.click(lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)), inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page])
|
| 410 |
|
| 411 |
# Keyword and repo input logic
|
| 412 |
keyword_btn.click(keyword_search_and_update, inputs=keyword_input, outputs=df_box)
|
|
|
|
| 431 |
def go_to_results_from_chatbot(keywords):
|
| 432 |
# Use the keywords to search and update the CSV, then display the DataFrame
|
| 433 |
df = use_keywords_to_search_and_update_csv(keywords)
|
| 434 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), df
|
| 435 |
|
| 436 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 437 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
| 438 |
go_to_results_btn.click(
|
| 439 |
go_to_results_from_chatbot,
|
| 440 |
inputs=keywords_output,
|
| 441 |
+
outputs=[chatbot_page, input_page, analysis_page, results_page, top3_page, results_df]
|
| 442 |
)
|
| 443 |
|
| 444 |
# Add logic for the new button on results_page
|
| 445 |
analyze_next_btn.click(show_combined_repo_and_llm, inputs=None, outputs=[combined_txt_results, llm_output_txt_results, results_df])
|
|
|
|
| 446 |
batch_btn.click(batch_analyze_and_select_top, inputs=None, outputs=[batch_info_txt, top3_txt, df_output])
|
| 447 |
+
|
| 448 |
+
def show_top3_page():
|
| 449 |
+
# Run batch analysis, get top 3, save to CSV, and return DataFrame
|
| 450 |
+
all_info_str, top3_str, df = batch_analyze_and_select_top()
|
| 451 |
+
import pandas as pd
|
| 452 |
+
import ast
|
| 453 |
+
try:
|
| 454 |
+
top3_ids = ast.literal_eval(top3_str)
|
| 455 |
+
if isinstance(top3_ids, str):
|
| 456 |
+
top3_ids = [top3_ids]
|
| 457 |
+
except Exception:
|
| 458 |
+
top3_ids = []
|
| 459 |
+
top3_df_data = pd.DataFrame({"repo id": top3_ids})
|
| 460 |
+
top3_df_data.to_csv("top3_repos.csv", index=False)
|
| 461 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), top3_df_data
|
| 462 |
+
|
| 463 |
+
show_top3_page_btn.click(show_top3_page, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page, top3_page, top3_df])
|
| 464 |
|
| 465 |
demo.launch()
|
chatbot_page.py
CHANGED
|
@@ -69,10 +69,9 @@ def extract_keywords_from_conversation(history):
|
|
| 69 |
with gr.Blocks() as chatbot_demo:
|
| 70 |
gr.Markdown("## Repo Recommendation Chatbot")
|
| 71 |
chatbot = gr.Chatbot()
|
| 72 |
-
# Initial assistant message
|
| 73 |
initial_message = "Hello! Please tell me about your ideal Hugging Face repo. What use case, preferred language, or features are you looking for?"
|
| 74 |
-
|
| 75 |
-
state = gr.State([["", initial_message], ["", dummy_question]]) # Start with assistant message and question
|
| 76 |
user_input = gr.Textbox(label="Your message", placeholder="Describe your ideal repo or answer the assistant's questions...")
|
| 77 |
send_btn = gr.Button("Send")
|
| 78 |
end_btn = gr.Button("End Chat and Extract Keywords")
|
|
@@ -87,8 +86,13 @@ with gr.Blocks() as chatbot_demo:
|
|
| 87 |
keywords = extract_keywords_from_conversation(history)
|
| 88 |
return keywords
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 91 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
|
|
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
chatbot_demo.launch()
|
|
|
|
| 69 |
with gr.Blocks() as chatbot_demo:
|
| 70 |
gr.Markdown("## Repo Recommendation Chatbot")
|
| 71 |
chatbot = gr.Chatbot()
|
| 72 |
+
# Initial assistant message only
|
| 73 |
initial_message = "Hello! Please tell me about your ideal Hugging Face repo. What use case, preferred language, or features are you looking for?"
|
| 74 |
+
state = gr.State([["", initial_message]]) # Only the initial assistant message
|
|
|
|
| 75 |
user_input = gr.Textbox(label="Your message", placeholder="Describe your ideal repo or answer the assistant's questions...")
|
| 76 |
send_btn = gr.Button("Send")
|
| 77 |
end_btn = gr.Button("End Chat and Extract Keywords")
|
|
|
|
| 86 |
keywords = extract_keywords_from_conversation(history)
|
| 87 |
return keywords
|
| 88 |
|
| 89 |
+
# Reset state to initial message when chatbot page is loaded
|
| 90 |
+
def reset_chat_state():
|
| 91 |
+
return [["", initial_message]]
|
| 92 |
+
|
| 93 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 94 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
| 95 |
+
chatbot_demo.load(reset_chat_state, inputs=None, outputs=state)
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
| 98 |
chatbot_demo.launch()
|