File size: 6,456 Bytes
2b06527
 
 
 
81527bf
b7820f3
1569a88
 
5583093
1569a88
81527bf
13d920e
1569a88
 
 
1f7c452
5583093
 
1569a88
996f9b9
87ee331
5583093
 
 
1569a88
5583093
 
 
 
1569a88
9ba711c
1569a88
5583093
 
9ba711c
5583093
b7820f3
 
 
 
 
 
 
 
 
 
 
2f1c002
 
 
b7820f3
9ba711c
9032e27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ba711c
2f1c002
9ba711c
9032e27
5583093
1cf682d
 
2b06527
9ba711c
2b06527
 
 
 
 
 
 
c73a13b
0176f2f
2b06527
 
 
 
8094c6b
fd6df86
 
2b06527
 
 
9ba711c
2b06527
 
5583093
1569a88
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import os
import spaces
from huggingface_hub import login
import gradio as gr
from smolagents import HfApiModel, CodeAgent, LiteLLMModel
from PIL import Image
import firecrawler
import rag

# Get secret for Antropic API
claude =  os.getenv('claude')

#Fetch tools
execute_firecrawl = firecrawler.FireCrawlTool()
retriever_tool = rag.retriever_tool 


agent = CodeAgent(
    tools=[execute_firecrawl, retriever_tool], 
    model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest", api_key=claude),
    max_steps=5
)


def get_answer(image, 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
        image (PIL): An image to investigate
        
    Returns:
        str: Detailed analysis report
    """
        # Check if image is None or not provided
    if image is None:
        return "Please upload an image before processing.", "Please upload an image before processing.", "Please upload an image before processing."
    
    # Ensure image is in PIL format
    if not isinstance(image, Image.Image):
        try:
            image = Image.open(image)
        except Exception as e:
            return f"Error opening image: {str(e)}", "Image processing failed.", "Please upload a valid image file."

    images = []
    images.append(image)

    
    # 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.
        
        INPUT CONTEXT
        URL under investigation: {url}
        User-provided situation description: {text}
        Attachment Image: Attached to the VLM submission (Optional supplementary context)
        
        ANALYSIS TOOLS
        retriever_tool : RAG tool that utilizes comprehensive scam information repository
        execute_firecrawl: Scrapes the contents of the url
        
        Access to verified scam databases
        Contextual information retrieval
        Up-to-date assistance resources
        Comparative scam pattern analysis

        
        ANALYSIS FRAMEWORK:
        
        RISK LEVEL
        Explicitly state an overall risk assessment (Low/Medium/High)
        INCLUDE image analysis insights if an image is provided
        Cross-reference with RAG tool scam repository.
        
        URL ANALYSIS
        Domain reputation assessment
        Technical red flags
        Registrar and hosting information insights
        Cross-reference with RAG tool database
        Verify against known scam patterns
        
        CONTENT EVALUATION
        Content quality assessment
        Linguistic and communication pattern analysis
        Consistency and professionalism evaluation
        Visual content analysis (if image attached)
        Compare against RAG tool's communication red flags
        
        SPECIFIC RED FLAGS
        List at least 5 concrete indicators of potential scam
        
        Utilize RAG tool to:
        Validate identified red flags
        Provide historical scam context
        Match against known scam signatures
        
        Categorize red flags (Technical, Financial, Communication)
        Incorporate visual evidence analysis if image provided
        
        RECOMMENDED ACTIONS
        Specific, actionable steps for user protection
        Leverage RAG tool for:
        Verified reporting channels
        Local and national assistance resources
        Recommended verification methods
        Personalized safety guidelines
        Image-specific caution recommendations if relevant
        
        ADDITIONAL INSIGHTS
        Contextual background information
        Potential motivations behind suspicious activity
        Broader pattern recognition
        Visual context interpretation (if image available)
        RAG tool-sourced trend analysis
        
        CRITICAL ANALYSIS GUIDELINES:
        Maintain objective, evidence-based analysis
        Talk in terms of risks rather than certainties
        Focus on user empowerment and protection
        Provide comprehensive yet clear recommendations
        Utilize RAG tool as primary reference and validation source
        
        IMAGE ANALYSIS PROTOCOL (IF APPLICABLE)
        Metadata examination
        Content authenticity assessment
        Potential manipulation indicators
        Contextual relevance to overall risk assessment
        RAG tool image forensics cross-reference
        
        ASSISTANCE RESOURCES
        Compile comprehensive list of support resources from RAG tool
        National fraud reporting centers
        Cybercrime units
        Consumer protection agencies
        Mental health and support services for scam victims
        '''
    
    answer = agent.run(full_prompt, images=images)
    

    print("Final output:")
    print(answer)
    return answer

# Gradio Interface (rest of the code remains the same)
with gr.Blocks(theme=gr.themes.Monochrome()) 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_image = gr.Image(label="Upload a suspicious screenshot (email, text message, advertisement etc)", type="pil")
            input_url = gr.Textbox(label="URLs", info="Please enter a suspicious URL", lines=3, value="https://fliojinews.xyz/?_lp=1&_token=uuid_28pp9h04s5la_28pp9h04s5la67e5d957781a19.77269004&product=Mirflect%20Gain&advertiser=Mirflect%20Gain%20i230")
            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? I read about it on a news page (screenshot attached)")
            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_image, input_url, input_text], 
        outputs=[t3]
    )

# Launch
demo.launch()