Spaces:
Sleeping
Sleeping
Update app.py
Browse files- Fix API Errors
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from
|
4 |
|
5 |
# Fetch the API data once at startup
|
6 |
API_URL = "https://dt074px2e9qbh.cloudfront.net/exploit-api.json"
|
@@ -11,41 +11,26 @@ except Exception as e:
|
|
11 |
flagged_addresses = []
|
12 |
print(f"Failed to load API data: {e}")
|
13 |
|
14 |
-
#
|
|
|
|
|
|
|
15 |
def infer_chain(address):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
elif address.startswith("bc1") or address.startswith("1") or address.startswith("3"):
|
20 |
-
return "Bitcoin"
|
21 |
-
elif address.startswith("T") and len(address) == 34:
|
22 |
-
return "Tron"
|
23 |
-
else:
|
24 |
-
return "Unknown"
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
"""Check if a cryptocurrency address is flagged in the Bybit hack database.
|
30 |
|
31 |
-
|
32 |
-
address: String representing the cryptocurrency address to check.
|
33 |
-
|
34 |
-
Returns:
|
35 |
-
String indicating if the address is flagged and its blockchain.
|
36 |
-
"""
|
37 |
chain = infer_chain(address)
|
38 |
-
flagged = False
|
39 |
|
40 |
# Check if the address is in the API data
|
41 |
-
for entry in flagged_addresses
|
42 |
-
if isinstance(entry, dict) and "address" in entry:
|
43 |
-
if entry["address"].lower() == address.lower():
|
44 |
-
flagged = True
|
45 |
-
chain = entry.get("chain", chain) # Override with API-provided chain if available
|
46 |
-
break
|
47 |
|
48 |
-
# Format the response
|
49 |
if flagged:
|
50 |
return f"Address {address} is Flagged ✅\nChain: {chain}\nStatus: Present in Bybit hack database"
|
51 |
else:
|
@@ -62,17 +47,8 @@ def chat_with_agent(user_input, chat_history, hf_token):
|
|
62 |
chat_history.append({"role": "assistant", "content": "Please enter a valid Hugging Face API token."})
|
63 |
return chat_history, ""
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
model=HfApiModel(model_id="mistralai/Mixtral-8x7B-Instruct-v0.1", token=hf_token),
|
68 |
-
tools=[check_flagged_address]
|
69 |
-
)
|
70 |
-
|
71 |
-
# Run the agent with the user's input
|
72 |
-
try:
|
73 |
-
response = agent.run(user_input)
|
74 |
-
except Exception as e:
|
75 |
-
response = f"Error: {str(e)}. Check your HF token or try again."
|
76 |
|
77 |
# Append as OpenAI-style messages
|
78 |
chat_history.append({"role": "user", "content": user_input})
|
@@ -134,18 +110,17 @@ with gr.Blocks(title="Bybit Hack Address Checker") as demo:
|
|
134 |
|
135 |
1. **Input an Address**: Enter a wallet address (e.g., Ethereum `0x...`, Bitcoin `bc1q...`, Tron `T...`) in the 'Check Address' tab.
|
136 |
2. **Provide HF Token**: Supply a Hugging Face API token to access the AI model powering the agent.
|
137 |
-
3. **Agent Processing**: The app uses a
|
138 |
-
4. **
|
139 |
-
5. **
|
140 |
-
6. **Result**: You’ll see whether the address is flagged ✅ or not ❌, its chain type, and if it’s present in the database.
|
141 |
|
142 |
### Why It’s Useful
|
143 |
- **Security**: Quickly check if an address you’re dealing with is linked to a known exploit.
|
144 |
- **Free & Open**: Uses free-tier AI and public data, making it accessible to anyone with an HF account.
|
145 |
-
- **Educational**: Demonstrates AI-driven blockchain analysis with
|
146 |
|
147 |
Get started by entering your HF token and an address in the 'Check Address' tab!
|
148 |
""")
|
149 |
|
150 |
# Launch the app
|
151 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
# Fetch the API data once at startup
|
6 |
API_URL = "https://dt074px2e9qbh.cloudfront.net/exploit-api.json"
|
|
|
11 |
flagged_addresses = []
|
12 |
print(f"Failed to load API data: {e}")
|
13 |
|
14 |
+
# Load LLM for blockchain inference
|
15 |
+
llm_pipeline = pipeline("text-generation", model="gpt-3.5-turbo") # You can use a larger or more appropriate model
|
16 |
+
|
17 |
+
# Function to infer chain using LLM
|
18 |
def infer_chain(address):
|
19 |
+
prompt = f"Identify the blockchain of the following cryptocurrency address: {address}"
|
20 |
+
result = llm_pipeline(prompt, max_length=50)
|
21 |
+
return result[0]["generated_text"].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Function to check if the address is flagged
|
24 |
+
def check_flagged_address(address: str):
|
25 |
+
"""Check if a cryptocurrency address is flagged in the Bybit hack database."""
|
|
|
26 |
|
27 |
+
# Infer the chain of the address
|
|
|
|
|
|
|
|
|
|
|
28 |
chain = infer_chain(address)
|
|
|
29 |
|
30 |
# Check if the address is in the API data
|
31 |
+
flagged = any(entry.get("address", "").lower() == address.lower() for entry in flagged_addresses)
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Format the response
|
34 |
if flagged:
|
35 |
return f"Address {address} is Flagged ✅\nChain: {chain}\nStatus: Present in Bybit hack database"
|
36 |
else:
|
|
|
47 |
chat_history.append({"role": "assistant", "content": "Please enter a valid Hugging Face API token."})
|
48 |
return chat_history, ""
|
49 |
|
50 |
+
# Run the address checker
|
51 |
+
response = check_flagged_address(user_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Append as OpenAI-style messages
|
54 |
chat_history.append({"role": "user", "content": user_input})
|
|
|
110 |
|
111 |
1. **Input an Address**: Enter a wallet address (e.g., Ethereum `0x...`, Bitcoin `bc1q...`, Tron `T...`) in the 'Check Address' tab.
|
112 |
2. **Provide HF Token**: Supply a Hugging Face API token to access the AI model powering the agent.
|
113 |
+
3. **Agent Processing**: The app uses a **language model** to infer the blockchain of the address (Ethereum, Bitcoin, Tron, etc.).
|
114 |
+
4. **Flag Check**: It then checks the address against a list of flagged addresses from the Elliptic Bybit hack dataset (`https://dt074px2e9qbh.cloudfront.net/exploit-api.json`).
|
115 |
+
5. **Result**: You’ll see whether the address is flagged ✅ or not ❌, its chain type, and if it’s present in the database.
|
|
|
116 |
|
117 |
### Why It’s Useful
|
118 |
- **Security**: Quickly check if an address you’re dealing with is linked to a known exploit.
|
119 |
- **Free & Open**: Uses free-tier AI and public data, making it accessible to anyone with an HF account.
|
120 |
+
- **Educational**: Demonstrates AI-driven blockchain analysis with a large language model.
|
121 |
|
122 |
Get started by entering your HF token and an address in the 'Check Address' tab!
|
123 |
""")
|
124 |
|
125 |
# Launch the app
|
126 |
+
demo.launch()
|