Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,29 +4,33 @@ from huggingface_hub import login
|
|
| 4 |
import gradio as gr
|
| 5 |
from smolagents import HfApiModel, CodeAgent, LiteLLMModel
|
| 6 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
claude = os.getenv('claude')
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
agent = CodeAgent(
|
| 16 |
-
tools=[],
|
| 17 |
model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest", api_key=claude),
|
| 18 |
max_steps=5
|
| 19 |
)
|
| 20 |
|
| 21 |
|
| 22 |
-
def get_answer(image):
|
| 23 |
"""
|
| 24 |
A function that takes any question as input and returns the answer using agent.run()
|
| 25 |
|
| 26 |
Args:
|
| 27 |
-
|
| 28 |
text (str): Additional context about the situation
|
| 29 |
-
|
| 30 |
|
| 31 |
Returns:
|
| 32 |
str: Detailed analysis report
|
|
@@ -47,10 +51,7 @@ def get_answer(image):
|
|
| 47 |
|
| 48 |
|
| 49 |
# Enhanced prompt with more specific instruction for detailed output
|
| 50 |
-
full_prompt =
|
| 51 |
-
IMAGE ANALYSIS
|
| 52 |
-
- Image contents assessment, use image_tool to obtain image OCR and label.
|
| 53 |
-
'''
|
| 54 |
|
| 55 |
answer = agent.run(full_prompt, images=images)
|
| 56 |
|
|
@@ -73,9 +74,9 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 73 |
|
| 74 |
with gr.Row():
|
| 75 |
with gr.Column(scale=1, min_width=300):
|
| 76 |
-
#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?")
|
| 77 |
input_image = gr.Image(label="Upload a suspicious screenshot (email, text message, advertisement etc)", type="pil")
|
| 78 |
-
|
|
|
|
| 79 |
btn = gr.Button("Process submission")
|
| 80 |
|
| 81 |
with gr.Column(scale=2, min_width=300):
|
|
@@ -83,7 +84,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 83 |
|
| 84 |
btn.click(
|
| 85 |
fn=get_answer,
|
| 86 |
-
inputs=[input_image],
|
| 87 |
outputs=[t3]
|
| 88 |
)
|
| 89 |
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from smolagents import HfApiModel, CodeAgent, LiteLLMModel
|
| 6 |
from PIL import Image
|
| 7 |
+
import firecrawler
|
| 8 |
+
import rag
|
| 9 |
+
import prompt
|
| 10 |
|
| 11 |
+
# Get secret for Antropic API
|
|
|
|
| 12 |
claude = os.getenv('claude')
|
| 13 |
|
| 14 |
+
#Fetch tools
|
| 15 |
+
execute_firecrawl = firecrawler.FireCrawlTool()
|
| 16 |
+
retriever_tool = rag.retriever_tool
|
| 17 |
|
| 18 |
|
| 19 |
agent = CodeAgent(
|
| 20 |
+
tools=[execute_firecrawl, retriever_tool],
|
| 21 |
model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest", api_key=claude),
|
| 22 |
max_steps=5
|
| 23 |
)
|
| 24 |
|
| 25 |
|
| 26 |
+
def get_answer(image, url, text):
|
| 27 |
"""
|
| 28 |
A function that takes any question as input and returns the answer using agent.run()
|
| 29 |
|
| 30 |
Args:
|
| 31 |
+
url (str): The URL to investigate
|
| 32 |
text (str): Additional context about the situation
|
| 33 |
+
image (PIL): An image to investigate
|
| 34 |
|
| 35 |
Returns:
|
| 36 |
str: Detailed analysis report
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
# Enhanced prompt with more specific instruction for detailed output
|
| 54 |
+
full_prompt = prompt.full_prompt
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
answer = agent.run(full_prompt, images=images)
|
| 57 |
|
|
|
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
with gr.Column(scale=1, min_width=300):
|
|
|
|
| 77 |
input_image = gr.Image(label="Upload a suspicious screenshot (email, text message, advertisement etc)", type="pil")
|
| 78 |
+
input_url = gr.Textbox(label="URLs", info="Please enter a suspicious URL", lines=3, value="https://fliojinews.xyz/9tKwgmC7")
|
| 79 |
+
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?")
|
| 80 |
btn = gr.Button("Process submission")
|
| 81 |
|
| 82 |
with gr.Column(scale=2, min_width=300):
|
|
|
|
| 84 |
|
| 85 |
btn.click(
|
| 86 |
fn=get_answer,
|
| 87 |
+
inputs=[input_image, input_url, input_text],
|
| 88 |
outputs=[t3]
|
| 89 |
)
|
| 90 |
|