Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,60 +18,6 @@ agent = CodeAgent(
|
|
| 18 |
max_steps=10
|
| 19 |
)
|
| 20 |
|
| 21 |
-
def format_detailed_response(answer):
|
| 22 |
-
"""
|
| 23 |
-
Format the agent's response into a structured, detailed output
|
| 24 |
-
|
| 25 |
-
Args:
|
| 26 |
-
answer (str): Raw response from the agent
|
| 27 |
-
|
| 28 |
-
Returns:
|
| 29 |
-
str: Formatted, structured response with clear sections
|
| 30 |
-
"""
|
| 31 |
-
try:
|
| 32 |
-
# Create a more structured response template
|
| 33 |
-
detailed_report = "# 🕵️ Scam Detection Analysis Report\n\n"
|
| 34 |
-
|
| 35 |
-
# Sections to extract and highlight
|
| 36 |
-
sections = {
|
| 37 |
-
"🚩 Risk Level": None,
|
| 38 |
-
"🌐 URL Analysis": None,
|
| 39 |
-
"📄 Content Evaluation": None,
|
| 40 |
-
"⚠️ Red Flags": [],
|
| 41 |
-
"🛡️ Recommended Actions": [],
|
| 42 |
-
"💡 Additional Insights": None
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
# Basic parsing to extract sections (you might want to use more advanced NLP)
|
| 46 |
-
for section, placeholder in sections.items():
|
| 47 |
-
section_name = section.split()[-1].lower().strip(':]')
|
| 48 |
-
start_index = answer.lower().find(section_name)
|
| 49 |
-
|
| 50 |
-
if start_index != -1:
|
| 51 |
-
# Find the next section or end of text
|
| 52 |
-
next_section_index = len(answer)
|
| 53 |
-
for other_section in sections:
|
| 54 |
-
other_start = answer.lower().find(other_section.split()[-1].lower())
|
| 55 |
-
if other_start > start_index and other_start < next_section_index:
|
| 56 |
-
next_section_index = other_start
|
| 57 |
-
|
| 58 |
-
# Extract section content
|
| 59 |
-
section_content = answer[start_index:next_section_index].strip()
|
| 60 |
-
sections[section] = section_content
|
| 61 |
-
|
| 62 |
-
# Construct the detailed report
|
| 63 |
-
for section, content in sections.items():
|
| 64 |
-
if content:
|
| 65 |
-
detailed_report += f"{section}:\n{content}\n\n"
|
| 66 |
-
|
| 67 |
-
# Fallback if parsing fails
|
| 68 |
-
if not any(sections.values()):
|
| 69 |
-
detailed_report += f"## Raw Analysis\n{answer}"
|
| 70 |
-
|
| 71 |
-
return detailed_report
|
| 72 |
-
|
| 73 |
-
except Exception as e:
|
| 74 |
-
return f"Error formatting response: {str(e)}\n\nOriginal Response:\n{answer}"
|
| 75 |
|
| 76 |
def get_answer(url, text):
|
| 77 |
"""
|
|
@@ -135,12 +81,10 @@ CRITICAL INSTRUCTIONS:
|
|
| 135 |
|
| 136 |
answer = agent.run(full_prompt)
|
| 137 |
|
| 138 |
-
# Format the response for better readability
|
| 139 |
-
formatted_answer = format_detailed_response(answer)
|
| 140 |
|
| 141 |
print("Final output:")
|
| 142 |
-
print(
|
| 143 |
-
return
|
| 144 |
|
| 145 |
# Gradio Interface (rest of the code remains the same)
|
| 146 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
|
|
| 18 |
max_steps=10
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def get_answer(url, text):
|
| 23 |
"""
|
|
|
|
| 81 |
|
| 82 |
answer = agent.run(full_prompt)
|
| 83 |
|
|
|
|
|
|
|
| 84 |
|
| 85 |
print("Final output:")
|
| 86 |
+
print(answer)
|
| 87 |
+
return answer
|
| 88 |
|
| 89 |
# Gradio Interface (rest of the code remains the same)
|
| 90 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|