Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -483,24 +483,19 @@ def process_problem(problem_description):
|
|
| 483 |
print(f"Category identified: {category_name} (Score: {cat_score:.3f}, Confident: {is_confident})")
|
| 484 |
|
| 485 |
# 2. Find Relevant Technologies (relative to problem, across ALL categories)
|
| 486 |
-
# Pass only the problem description now
|
| 487 |
relevant_technologies_df = find_relevant_technologies(problem_description)
|
| 488 |
print(f"Found {len(relevant_technologies_df)} relevant technologies based on problem similarity.")
|
| 489 |
|
| 490 |
tech_output = ""
|
| 491 |
if not relevant_technologies_df.empty:
|
| 492 |
-
# Modify the header to clarify the selection criteria
|
| 493 |
tech_output += f"### Top {len(relevant_technologies_df)} Most Relevant Technologies (selected based on similarity to your problem):\n\n"
|
| 494 |
for _, row in relevant_technologies_df.iterrows():
|
| 495 |
-
# Clean name for display
|
| 496 |
tech_name = re.sub(r'^- Title\s*:\s*', '', str(row.get('technology', 'N/A'))).strip()
|
| 497 |
problem_relevance = row.get('similarity_score_problem', 0.0)
|
| 498 |
-
tech_output += f"- **{tech_name}** (Problem Relevance: {problem_relevance:.3f})\n"
|
| 499 |
-
# Optionally show original category for info
|
| 500 |
original_cats = str(row.get('category', 'Unknown')).strip()
|
| 501 |
if original_cats:
|
| 502 |
tech_output += f" *Original Category listed as: {original_cats}*\n"
|
| 503 |
-
|
| 504 |
tech_output += "\n---\n" # Add separator
|
| 505 |
else:
|
| 506 |
tech_output = "Could not identify any relevant technologies based on the problem description.\n\n---\n"
|
|
@@ -512,30 +507,35 @@ def process_problem(problem_description):
|
|
| 512 |
|
| 513 |
pairs_output = ""
|
| 514 |
if top_pairs:
|
| 515 |
-
# Clarify the source of pairs
|
| 516 |
pairs_output += f"### Top {len(top_pairs)} Technology Pairs (selected from the relevant technologies above, based on their inter-similarity):\n\n"
|
| 517 |
for pair_names, score in top_pairs:
|
| 518 |
-
pairs_output += f"- **{pair_names[0]} + {pair_names[1]}** (Inter-Similarity: {score:.3f})\n"
|
| 519 |
pairs_output += "\n---\n"
|
| 520 |
-
#
|
| 521 |
-
# else:
|
| 522 |
-
# pairs_output = "Could not identify relevant technology pairs for search (need >= 2 relevant technologies).\n\n---\n"
|
| 523 |
|
| 524 |
# 4. Search for Solutions using the Top Pairs
|
| 525 |
-
# Pass the original problem description for context if needed by the search function
|
| 526 |
solution_output = search_solutions_for_pairs(problem_description, top_pairs)
|
| 527 |
print("API search for solutions completed.")
|
| 528 |
|
| 529 |
-
# 5. Combine Outputs for Gradio
|
| 530 |
final_output = (
|
| 531 |
-
f"## Analysis Results for: {problem_description[:150]}\n\n"
|
| 532 |
f"{category_output}\n\n"
|
| 533 |
f"{tech_output}"
|
| 534 |
-
#
|
| 535 |
-
f"{pairs_output if top_pairs else 'No technology pairs identified to search with.|\n|\n---|\n'}"
|
| 536 |
-
f"{solution_output}"
|
| 537 |
)
|
| 538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
print("--- Processing finished ---")
|
| 540 |
return final_output
|
| 541 |
|
|
|
|
| 483 |
print(f"Category identified: {category_name} (Score: {cat_score:.3f}, Confident: {is_confident})")
|
| 484 |
|
| 485 |
# 2. Find Relevant Technologies (relative to problem, across ALL categories)
|
|
|
|
| 486 |
relevant_technologies_df = find_relevant_technologies(problem_description)
|
| 487 |
print(f"Found {len(relevant_technologies_df)} relevant technologies based on problem similarity.")
|
| 488 |
|
| 489 |
tech_output = ""
|
| 490 |
if not relevant_technologies_df.empty:
|
|
|
|
| 491 |
tech_output += f"### Top {len(relevant_technologies_df)} Most Relevant Technologies (selected based on similarity to your problem):\n\n"
|
| 492 |
for _, row in relevant_technologies_df.iterrows():
|
|
|
|
| 493 |
tech_name = re.sub(r'^- Title\s*:\s*', '', str(row.get('technology', 'N/A'))).strip()
|
| 494 |
problem_relevance = row.get('similarity_score_problem', 0.0)
|
| 495 |
+
tech_output += f"- **{tech_name}** (Problem Relevance: {problem_relevance:.3f})\n"
|
|
|
|
| 496 |
original_cats = str(row.get('category', 'Unknown')).strip()
|
| 497 |
if original_cats:
|
| 498 |
tech_output += f" *Original Category listed as: {original_cats}*\n"
|
|
|
|
| 499 |
tech_output += "\n---\n" # Add separator
|
| 500 |
else:
|
| 501 |
tech_output = "Could not identify any relevant technologies based on the problem description.\n\n---\n"
|
|
|
|
| 507 |
|
| 508 |
pairs_output = ""
|
| 509 |
if top_pairs:
|
|
|
|
| 510 |
pairs_output += f"### Top {len(top_pairs)} Technology Pairs (selected from the relevant technologies above, based on their inter-similarity):\n\n"
|
| 511 |
for pair_names, score in top_pairs:
|
| 512 |
+
pairs_output += f"- **{pair_names[0]} + {pair_names[1]}** (Inter-Similarity: {score:.3f})\n"
|
| 513 |
pairs_output += "\n---\n"
|
| 514 |
+
# Note: The "else" case message will be added during final output assembly
|
|
|
|
|
|
|
| 515 |
|
| 516 |
# 4. Search for Solutions using the Top Pairs
|
|
|
|
| 517 |
solution_output = search_solutions_for_pairs(problem_description, top_pairs)
|
| 518 |
print("API search for solutions completed.")
|
| 519 |
|
| 520 |
+
# 5. Combine Outputs for Gradio --- CORRECTED SECTION ---
|
| 521 |
final_output = (
|
| 522 |
+
f"## Analysis Results for: \"{problem_description[:150]}...\"\n\n"
|
| 523 |
f"{category_output}\n\n"
|
| 524 |
f"{tech_output}"
|
| 525 |
+
# Intentionally left blank line above for structure
|
|
|
|
|
|
|
| 526 |
)
|
| 527 |
|
| 528 |
+
# Add the pairs section conditionally - This avoids the backslash issue
|
| 529 |
+
if top_pairs:
|
| 530 |
+
final_output += pairs_output # pairs_output already contains formatting and separators
|
| 531 |
+
else:
|
| 532 |
+
# Add the "no pairs" message directly here
|
| 533 |
+
final_output += "No technology pairs identified to search with.\n\n---\n"
|
| 534 |
+
|
| 535 |
+
# Add the solution output
|
| 536 |
+
final_output += solution_output
|
| 537 |
+
# --- END OF CORRECTION ---
|
| 538 |
+
|
| 539 |
print("--- Processing finished ---")
|
| 540 |
return final_output
|
| 541 |
|