xyizko commited on
Commit
eb12ccd
·
verified ·
1 Parent(s): 3d10eeb

Update app.py

Browse files

- fix api issues

Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -1,6 +1,5 @@
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,21 +10,33 @@ except Exception as e:
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)
@@ -48,7 +59,7 @@ def chat_with_agent(user_input, chat_history, hf_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})
 
1
  import gradio as gr
2
  import requests
 
3
 
4
  # Fetch the API data once at startup
5
  API_URL = "https://dt074px2e9qbh.cloudfront.net/exploit-api.json"
 
10
  flagged_addresses = []
11
  print(f"Failed to load API data: {e}")
12
 
13
+ # Function to infer the blockchain using Hugging Face API
14
+ def infer_chain(address, hf_token):
15
+ headers = {
16
+ "Authorization": f"Bearer {hf_token}"
17
+ }
18
  prompt = f"Identify the blockchain of the following cryptocurrency address: {address}"
19
+
20
+ # Make the request to Hugging Face's Inference API
21
+ try:
22
+ response = requests.post(
23
+ "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1",
24
+ headers=headers,
25
+ json={"inputs": prompt}
26
+ )
27
+ response.raise_for_status()
28
+ result = response.json()
29
+ # Return the inferred blockchain (if available)
30
+ return result[0]["generated_text"].strip()
31
+ except Exception as e:
32
+ return "Unknown" # Fallback if there's an error
33
 
34
  # Function to check if the address is flagged
35
+ def check_flagged_address(address: str, hf_token: str):
36
  """Check if a cryptocurrency address is flagged in the Bybit hack database."""
37
 
38
  # Infer the chain of the address
39
+ chain = infer_chain(address, hf_token)
40
 
41
  # Check if the address is in the API data
42
  flagged = any(entry.get("address", "").lower() == address.lower() for entry in flagged_addresses)
 
59
  return chat_history, ""
60
 
61
  # Run the address checker
62
+ response = check_flagged_address(user_input, hf_token)
63
 
64
  # Append as OpenAI-style messages
65
  chat_history.append({"role": "user", "content": user_input})