Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,9 @@ def process_repo_input(text):
|
|
| 39 |
last_repo_ids = []
|
| 40 |
current_repo_idx = 0
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
def process_repo_input_and_store(text):
|
| 43 |
global last_repo_ids, current_repo_idx
|
| 44 |
if not text:
|
|
@@ -124,16 +127,19 @@ def show_combined_repo_and_llm():
|
|
| 124 |
return combined_content, summary, df
|
| 125 |
|
| 126 |
def go_to_analysis():
|
| 127 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 128 |
|
| 129 |
def go_to_input():
|
| 130 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 131 |
|
| 132 |
def go_to_chatbot():
|
| 133 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 134 |
|
| 135 |
def go_to_start():
|
| 136 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
|
| 139 |
df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"],
|
|
@@ -164,12 +170,29 @@ def extract_keywords_from_conversation(history):
|
|
| 164 |
conversation = "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[1]])
|
| 165 |
prompt = (
|
| 166 |
"Given the following conversation between a user and an assistant about finding an ideal open-source repo, "
|
| 167 |
-
"extract about 5 keywords that
|
| 168 |
"Return only the keywords as a comma-separated list.\n\nConversation:\n" + conversation
|
| 169 |
)
|
| 170 |
keywords = analyze_code(prompt)
|
| 171 |
return keywords
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
with gr.Blocks() as demo:
|
| 174 |
page_state = gr.State(0)
|
| 175 |
|
|
@@ -212,16 +235,27 @@ with gr.Blocks() as demo:
|
|
| 212 |
send_btn = gr.Button("Send")
|
| 213 |
end_btn = gr.Button("End Chat and Extract Keywords")
|
| 214 |
keywords_output = gr.Textbox(label="Extracted Keywords for Repo Search", interactive=False)
|
|
|
|
| 215 |
back_to_start_btn3 = gr.Button("Back to Start")
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# Navigation logic
|
| 218 |
-
option_a_btn.click(go_to_input, inputs=None, outputs=[start_page, input_page, chatbot_page])
|
| 219 |
-
option_b_btn.click(go_to_chatbot, inputs=None, outputs=[start_page, input_page, chatbot_page])
|
| 220 |
-
next_btn.click(go_to_analysis, inputs=None, outputs=[input_page, analysis_page, chatbot_page])
|
| 221 |
-
back_btn.click(go_to_input, inputs=None, outputs=[input_page, analysis_page, chatbot_page])
|
| 222 |
-
back_to_start_btn.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page])
|
| 223 |
-
back_to_start_btn2.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page])
|
| 224 |
-
back_to_start_btn3.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page])
|
|
|
|
| 225 |
|
| 226 |
# Keyword and repo input logic
|
| 227 |
keyword_btn.click(keyword_search_and_update, inputs=keyword_input, outputs=df_box)
|
|
@@ -238,9 +272,18 @@ with gr.Blocks() as demo:
|
|
| 238 |
|
| 239 |
def end_chat(history):
|
| 240 |
keywords = extract_keywords_from_conversation(history)
|
|
|
|
|
|
|
|
|
|
| 241 |
return keywords
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 244 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
|
|
|
| 245 |
|
| 246 |
demo.launch()
|
|
|
|
| 39 |
last_repo_ids = []
|
| 40 |
current_repo_idx = 0
|
| 41 |
|
| 42 |
+
# Store extracted keywords for the chatbot flow
|
| 43 |
+
generated_keywords = []
|
| 44 |
+
|
| 45 |
def process_repo_input_and_store(text):
|
| 46 |
global last_repo_ids, current_repo_idx
|
| 47 |
if not text:
|
|
|
|
| 127 |
return combined_content, summary, df
|
| 128 |
|
| 129 |
def go_to_analysis():
|
| 130 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 131 |
|
| 132 |
def go_to_input():
|
| 133 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 134 |
|
| 135 |
def go_to_chatbot():
|
| 136 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 137 |
|
| 138 |
def go_to_start():
|
| 139 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 140 |
+
|
| 141 |
+
def go_to_results():
|
| 142 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 143 |
|
| 144 |
repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
|
| 145 |
df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"],
|
|
|
|
| 170 |
conversation = "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[1]])
|
| 171 |
prompt = (
|
| 172 |
"Given the following conversation between a user and an assistant about finding an ideal open-source repo, "
|
| 173 |
+
"extract about 5 keywords that would be most useful for searching Hugging Face repos to find the most relevant results for the user. "
|
| 174 |
"Return only the keywords as a comma-separated list.\n\nConversation:\n" + conversation
|
| 175 |
)
|
| 176 |
keywords = analyze_code(prompt)
|
| 177 |
return keywords
|
| 178 |
|
| 179 |
+
def use_keywords_to_search_and_update_csv(keywords):
|
| 180 |
+
global last_repo_ids, current_repo_idx
|
| 181 |
+
if not keywords:
|
| 182 |
+
return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
|
| 183 |
+
# Use the keywords to search for repos
|
| 184 |
+
repo_ids = search_top_spaces(keywords, limit=5)
|
| 185 |
+
last_repo_ids = repo_ids
|
| 186 |
+
current_repo_idx = 0
|
| 187 |
+
csv_filename = "repo_ids.csv"
|
| 188 |
+
with open(csv_filename, mode="w", newline='', encoding="utf-8") as csvfile:
|
| 189 |
+
writer = csv.writer(csvfile)
|
| 190 |
+
writer.writerow(["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
|
| 191 |
+
for repo_id in repo_ids:
|
| 192 |
+
writer.writerow([repo_id, "", "", "", ""])
|
| 193 |
+
df = read_csv_as_text(csv_filename)
|
| 194 |
+
return df
|
| 195 |
+
|
| 196 |
with gr.Blocks() as demo:
|
| 197 |
page_state = gr.State(0)
|
| 198 |
|
|
|
|
| 235 |
send_btn = gr.Button("Send")
|
| 236 |
end_btn = gr.Button("End Chat and Extract Keywords")
|
| 237 |
keywords_output = gr.Textbox(label="Extracted Keywords for Repo Search", interactive=False)
|
| 238 |
+
go_to_results_btn = gr.Button("Find Repos with These Keywords")
|
| 239 |
back_to_start_btn3 = gr.Button("Back to Start")
|
| 240 |
|
| 241 |
+
# --- Page 4: Results after Chatbot ---
|
| 242 |
+
with gr.Column(visible=False) as results_page:
|
| 243 |
+
gr.Markdown("## Repo Results Based on Your Conversation")
|
| 244 |
+
results_df = gr.Dataframe(
|
| 245 |
+
headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"],
|
| 246 |
+
datatype=["str", "str", "str", "str", "str", "str"]
|
| 247 |
+
)
|
| 248 |
+
back_to_start_btn4 = gr.Button("Back to Start")
|
| 249 |
+
|
| 250 |
# Navigation logic
|
| 251 |
+
option_a_btn.click(go_to_input, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 252 |
+
option_b_btn.click(go_to_chatbot, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 253 |
+
next_btn.click(go_to_analysis, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page])
|
| 254 |
+
back_btn.click(go_to_input, inputs=None, outputs=[input_page, analysis_page, chatbot_page, results_page])
|
| 255 |
+
back_to_start_btn.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 256 |
+
back_to_start_btn2.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 257 |
+
back_to_start_btn3.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 258 |
+
back_to_start_btn4.click(go_to_start, inputs=None, outputs=[start_page, input_page, chatbot_page, results_page])
|
| 259 |
|
| 260 |
# Keyword and repo input logic
|
| 261 |
keyword_btn.click(keyword_search_and_update, inputs=keyword_input, outputs=df_box)
|
|
|
|
| 272 |
|
| 273 |
def end_chat(history):
|
| 274 |
keywords = extract_keywords_from_conversation(history)
|
| 275 |
+
global generated_keywords
|
| 276 |
+
generated_keywords.clear()
|
| 277 |
+
generated_keywords.extend([k.strip() for k in keywords.split(",") if k.strip()])
|
| 278 |
return keywords
|
| 279 |
|
| 280 |
+
def go_to_results_from_chatbot(keywords):
|
| 281 |
+
# Use the keywords to search and update the CSV, then display the DataFrame
|
| 282 |
+
df = use_keywords_to_search_and_update_csv(keywords)
|
| 283 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), df
|
| 284 |
+
|
| 285 |
send_btn.click(user_send, inputs=[user_input, state], outputs=[chatbot, state, user_input])
|
| 286 |
end_btn.click(end_chat, inputs=state, outputs=keywords_output)
|
| 287 |
+
go_to_results_btn.click(go_to_results_from_chatbot, inputs=keywords_output, outputs=[chatbot_page, input_page, analysis_page, results_page, results_df])
|
| 288 |
|
| 289 |
demo.launch()
|