Spaces:
Running
on
Zero
Running
on
Zero
Adding GPU support for hugging face
Browse files- app.py +9 -0
- instruction_classifier.py +9 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,14 @@ import gradio as gr
|
|
2 |
from datetime import datetime
|
3 |
from agent import tool_agent_loop, Email
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# System prompt that shows what tools the assistant has access to
|
6 |
SYSTEM_PROMPT = """You are a helpful personal assistant with access to some email client tools which makes you a helpful personal email agent. The tools you have access to are:
|
7 |
get_emails()
|
@@ -56,6 +64,7 @@ INBOX[2].timestamp = "2025-02-01 10:30:00"
|
|
56 |
# This file now focuses on frontend components only
|
57 |
# Backend logic has been moved to agent.py
|
58 |
|
|
|
59 |
def submit_attack(attack_subject, attack_body, model_name="claude-3-5-sonnet-20241022"):
|
60 |
"""Process the attacker's email and return a response using the tool agent loop"""
|
61 |
try:
|
|
|
2 |
from datetime import datetime
|
3 |
from agent import tool_agent_loop, Email
|
4 |
|
5 |
+
try:
|
6 |
+
import spaces
|
7 |
+
except ImportError:
|
8 |
+
# Create a no-op decorator if spaces is not available
|
9 |
+
def spaces_gpu_decorator(func):
|
10 |
+
return func
|
11 |
+
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})()
|
12 |
+
|
13 |
# System prompt that shows what tools the assistant has access to
|
14 |
SYSTEM_PROMPT = """You are a helpful personal assistant with access to some email client tools which makes you a helpful personal email agent. The tools you have access to are:
|
15 |
get_emails()
|
|
|
64 |
# This file now focuses on frontend components only
|
65 |
# Backend logic has been moved to agent.py
|
66 |
|
67 |
+
@spaces.GPU
|
68 |
def submit_attack(attack_subject, attack_body, model_name="claude-3-5-sonnet-20241022"):
|
69 |
"""Process the attacker's email and return a response using the tool agent loop"""
|
70 |
try:
|
instruction_classifier.py
CHANGED
@@ -22,6 +22,14 @@ try:
|
|
22 |
except ImportError:
|
23 |
hf_hub_download = None
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# Import required components from utils.py
|
26 |
from utils import (
|
27 |
TransformerInstructionClassifier,
|
@@ -146,6 +154,7 @@ class InstructionClassifierSanitizer:
|
|
146 |
self.model.to(self.device)
|
147 |
self.model.eval()
|
148 |
|
|
|
149 |
def sanitize_tool_output(self, tool_output: str) -> str:
|
150 |
"""
|
151 |
Main sanitization function that processes tool output and removes instruction content
|
|
|
22 |
except ImportError:
|
23 |
hf_hub_download = None
|
24 |
|
25 |
+
try:
|
26 |
+
import spaces
|
27 |
+
except ImportError:
|
28 |
+
# Create a no-op decorator if spaces is not available
|
29 |
+
def spaces_gpu_decorator(func):
|
30 |
+
return func
|
31 |
+
spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})()
|
32 |
+
|
33 |
# Import required components from utils.py
|
34 |
from utils import (
|
35 |
TransformerInstructionClassifier,
|
|
|
154 |
self.model.to(self.device)
|
155 |
self.model.eval()
|
156 |
|
157 |
+
@spaces.GPU
|
158 |
def sanitize_tool_output(self, tool_output: str) -> str:
|
159 |
"""
|
160 |
Main sanitization function that processes tool output and removes instruction content
|
requirements.txt
CHANGED
@@ -12,3 +12,4 @@ tqdm>=4.65.0
|
|
12 |
datasets>=2.12.0
|
13 |
accelerate>=0.20.0
|
14 |
huggingface_hub>=0.20.0
|
|
|
|
12 |
datasets>=2.12.0
|
13 |
accelerate>=0.20.0
|
14 |
huggingface_hub>=0.20.0
|
15 |
+
spaces
|