Spaces:
Sleeping
Sleeping
File size: 4,040 Bytes
2b06527 2e05e88 592cd81 2b06527 81527bf 5583093 13d920e 5583093 81527bf 13d920e 5e56f62 9ba711c 5583093 8ca9291 5583093 9ba711c 52d1247 81527bf 8ca9291 5583093 8c45b9a 5583093 9ba711c 5583093 9ba711c 5583093 9ba711c fcc725a 21fcde9 fcc725a 21fcde9 fcc725a 21fcde9 fcc725a 21fcde9 9ba711c 5583093 1cf682d 2b06527 9ba711c 00339b8 2b06527 c73a13b 94f6820 2b06527 5c3749a 2b06527 9ba711c 2b06527 5583093 d043066 2b06527 9ba711c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | import os
import spaces
import firecrawler
import rag
from huggingface_hub import login
import gradio as gr
from smolagents import HfApiModel, CodeAgent, LiteLLMModel
# Login to Hugging Face for access to LLama or Claude token to access Claude
login(token = os.getenv('hf_login'))
claude = os.getenv('claude')
#Fetch tools
execute_firecrawl = firecrawler.FireCrawlTool()
retriever_tool = rag.retriever_tool
#meta-llama/Llama-3.3-70B-Instruct
agent = CodeAgent(
tools=[execute_firecrawl, retriever_tool],
model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest", api_key=claude),
#model=HfApiModel(),
max_steps=10
)
def get_answer(url, text):
"""
A function that takes any question as input and returns the answer using agent.run()
Args:
url (str): The URL to investigate
text (str): Additional context about the situation
Returns:
str: Detailed analysis report
"""
# Enhanced prompt with more specific instruction for detailed output
full_prompt = f'''
COMPREHENSIVE SCAM DETECTION ANALYSIS
Objective: Provide a meticulously detailed, structured assessment of potential online risks.
ANALYSIS FRAMEWORK:
1. RISK LEVEL
- Explicitly state an overall risk assessment (Low/Medium/High)
2. URL ANALYSIS
- Detailed breakdown of URL characteristics
- Domain reputation assessment
- Technical red flags
- Registrar and hosting information insights
3. CONTENT EVALUATION
- Content quality assessment (use execute_firecrawl to retrieve contents sample)
- Linguistic and communication pattern analysis
- Consistency and professionalism evaluation
4. SPECIFIC RED FLAGS
- List at least 5 concrete indicators of potential scam
- Use Scamwatch reference material (use retriever_tool)
- Provide specific evidence for each red flag
- Categorize red flags (e.g., Technical, Financial, Communication)
5. RECOMMENDED ACTIONS
- Specific, actionable steps for user protection
- Use Scamwatch reference material (use retriever_tool)
- Recommended verification methods
- Suggested reporting channels
- Personal safety guidelines
6. ADDITIONAL INSIGHTS
- Contextual background information
- Potential motivations behind suspicious activity
- Broader pattern recognition
CONTEXT:
- URL under investigation: {url}
- User-provided situation description: {text}
CRITICAL INSTRUCTIONS:
- Maintain objective, evidence-based analysis
- Talk in terms of risks rather then certainties.
- Focus on user empowerment and protection
- Use the retriever_tool tool to look up Scamwatch reference information scam types, reporting scams etc. Where possible prioritise this infomration.
'''
answer = agent.run(full_prompt)
print("Final output:")
print(answer)
return answer
# Gradio Interface (rest of the code remains the same)
with gr.Blocks() as demo:
theme=gr.themes.Monochrome()
with gr.Row():
with gr.Column(scale=1, min_width=300):
gr.Markdown(
"""
# ScamShield (agent edition)
🛡️ A tool to help users identify scam red flags.
""")
with gr.Row():
with gr.Column(scale=1, min_width=300):
input_text = gr.Textbox(label="Description", info="Please describe your concerns regarding the situation", lines=3, value="Is this website a reliable source of investment information?")
input_url = gr.Textbox(label="URLs", info="Please enter a suspicious URL", lines=3, value="https://fliojinews.xyz/9tKwgmC7")
btn = gr.Button("Process submission")
with gr.Column(scale=2, min_width=300):
t3 = gr.Textbox(label="Advice", lines=10)
btn.click(
fn=get_answer,
inputs=[input_url, input_text],
outputs=[t3]
)
# Launch
demo.launch() |