Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +267 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os, json, time, sqlite3, requests, io, csv
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from typing import List, Dict
|
| 6 |
+
from sentence_transformers import SentenceTransformer
|
| 7 |
+
|
| 8 |
+
# ---- DAO CONFIG ----
|
| 9 |
+
DAO_ADDRESS = os.environ.get("DAO_ADDRESS", "0xE2F60eEEd806Cb2790c0685334D0b95417c386E0")
|
| 10 |
+
FIELD_TOKEN = os.environ.get("FIELD_TOKEN", "")
|
| 11 |
+
ARBITRUM_RPC = os.environ.get("ARBITRUM_RPC", "https://arb1.arbitrum.io/rpc")
|
| 12 |
+
|
| 13 |
+
TELEMETRY_WEBHOOK = os.environ.get("TELEMETRY_WEBHOOK", "") # point to FastAPI server /usage
|
| 14 |
+
PREMIUM_KEY = os.environ.get("PREMIUM_KEY", "")
|
| 15 |
+
FREE_LIMIT = int(os.environ.get("FREE_LIMIT", "20"))
|
| 16 |
+
|
| 17 |
+
DB_PATH = os.environ.get("DB_PATH", "inneri_reskill.db")
|
| 18 |
+
EMBED_MODEL = os.environ.get("EMBED_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
|
| 19 |
+
TOP_K = int(os.environ.get("TOP_K", "5"))
|
| 20 |
+
|
| 21 |
+
def db():
|
| 22 |
+
conn = sqlite3.connect(DB_PATH)
|
| 23 |
+
conn.execute("PRAGMA foreign_keys = ON;")
|
| 24 |
+
return conn
|
| 25 |
+
|
| 26 |
+
def init_db():
|
| 27 |
+
conn = db(); cur = conn.cursor()
|
| 28 |
+
cur.execute("CREATE TABLE IF NOT EXISTS users(user_id TEXT PRIMARY KEY, balance_cents INTEGER DEFAULT 0);")
|
| 29 |
+
cur.execute("CREATE TABLE IF NOT EXISTS guides(id INTEGER PRIMARY KEY AUTOINCREMENT, owner_id TEXT, title TEXT, text TEXT, tags TEXT, namespace TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
|
| 30 |
+
cur.execute("CREATE TABLE IF NOT EXISTS embeds(id INTEGER PRIMARY KEY AUTOINCREMENT, guide_id INTEGER, namespace TEXT, dim INTEGER, vec BLOB, FOREIGN KEY(guide_id) REFERENCES guides(id) ON DELETE CASCADE);")
|
| 31 |
+
cur.execute("CREATE TABLE IF NOT EXISTS traces(id INTEGER PRIMARY KEY AUTOINCREMENT, trace_id TEXT, user_id TEXT, question TEXT, answer TEXT, sources TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
|
| 32 |
+
cur.execute("CREATE TABLE IF NOT EXISTS usage_credits(user_id TEXT, guide_id INTEGER, credits REAL, period TEXT);")
|
| 33 |
+
conn.commit(); conn.close()
|
| 34 |
+
|
| 35 |
+
def ensure_user(user_id:str):
|
| 36 |
+
conn = db(); cur = conn.cursor()
|
| 37 |
+
cur.execute("INSERT OR IGNORE INTO users(user_id,balance_cents) VALUES(?,0)", (user_id,))
|
| 38 |
+
conn.commit(); conn.close()
|
| 39 |
+
|
| 40 |
+
_embedder = None
|
| 41 |
+
def get_embedder():
|
| 42 |
+
global _embedder
|
| 43 |
+
if _embedder is None:
|
| 44 |
+
_embedder = SentenceTransformer(EMBED_MODEL)
|
| 45 |
+
return _embedder
|
| 46 |
+
|
| 47 |
+
def embed_texts(texts: List[str]):
|
| 48 |
+
return np.array(get_embedder().encode(texts, show_progress_bar=False, normalize_embeddings=True), dtype=np.float32)
|
| 49 |
+
|
| 50 |
+
def vec_to_blob(vec: np.ndarray) -> bytes:
|
| 51 |
+
return vec.astype(np.float32).tobytes()
|
| 52 |
+
|
| 53 |
+
def blob_to_vec(blob: bytes) -> np.ndarray:
|
| 54 |
+
return np.frombuffer(blob, dtype=np.float32)
|
| 55 |
+
|
| 56 |
+
def add_guide(owner_id:str, title:str, text:str, tags:str, namespace:str):
|
| 57 |
+
ensure_user(owner_id)
|
| 58 |
+
conn = db(); cur = conn.cursor()
|
| 59 |
+
cur.execute("INSERT INTO guides(owner_id,title,text,tags,namespace) VALUES(?,?,?,?,?)",(owner_id, title, text, tags, namespace))
|
| 60 |
+
gid = cur.lastrowid
|
| 61 |
+
vec = embed_texts([text])[0]
|
| 62 |
+
cur.execute("INSERT INTO embeds(guide_id,namespace,dim,vec) VALUES(?,?,?,?)",(gid, namespace, vec.shape[0], vec_to_blob(vec)))
|
| 63 |
+
conn.commit(); conn.close()
|
| 64 |
+
return gid
|
| 65 |
+
|
| 66 |
+
def list_guides(namespace:str):
|
| 67 |
+
conn = db(); cur = conn.cursor()
|
| 68 |
+
cur.execute("SELECT id, owner_id, title, tags, created_at FROM guides WHERE namespace=? ORDER BY created_at DESC",(namespace,))
|
| 69 |
+
rows = cur.fetchall(); conn.close()
|
| 70 |
+
return rows
|
| 71 |
+
|
| 72 |
+
def retrieve(question:str, namespace:str, top_k:int=TOP_K)->List[Dict]:
|
| 73 |
+
qv = embed_texts([question])[0]
|
| 74 |
+
conn = db(); cur = conn.cursor()
|
| 75 |
+
cur.execute("SELECT e.id, e.guide_id, e.vec, g.title, g.owner_id, g.text FROM embeds e JOIN guides g ON e.guide_id=g.id WHERE e.namespace=?",(namespace,))
|
| 76 |
+
rows = cur.fetchall(); conn.close()
|
| 77 |
+
if not rows: return []
|
| 78 |
+
mat = np.stack([blob_to_vec(r[2]) for r in rows])
|
| 79 |
+
sims = mat @ qv
|
| 80 |
+
idx = np.argsort(-sims)[:top_k]
|
| 81 |
+
results = []
|
| 82 |
+
for i in idx:
|
| 83 |
+
_, gid, _, title, owner, text = rows[int(i)]
|
| 84 |
+
results.append({"guide_id": int(gid), "owner": owner, "title": title or "Untitled", "text": text, "score": float(sims[int(i)])})
|
| 85 |
+
return results
|
| 86 |
+
|
| 87 |
+
def synthesize_answer(question:str, contexts:List[Dict])->str:
|
| 88 |
+
bullets = []
|
| 89 |
+
for i,c in enumerate(contexts):
|
| 90 |
+
snippet = c["text"][:400].replace("\n"," ").strip()
|
| 91 |
+
bullets.append(f"[{i+1}] {c['title']}: {snippet}")
|
| 92 |
+
return "Q: " + question + "\n\nGuides:\n" + "\n".join(bullets)
|
| 93 |
+
|
| 94 |
+
def record_usage(ctx:List[Dict], period:str):
|
| 95 |
+
conn = db(); cur = conn.cursor()
|
| 96 |
+
total = sum(max(0.0, c["score"]) for c in ctx) or 1.0
|
| 97 |
+
for c in ctx:
|
| 98 |
+
w = max(0.0, c["score"])/total
|
| 99 |
+
cur.execute("INSERT INTO usage_credits(user_id, guide_id, credits, period) VALUES(?,?,?,?)",
|
| 100 |
+
(c["owner"], c["guide_id"], w, period))
|
| 101 |
+
conn.commit(); conn.close()
|
| 102 |
+
|
| 103 |
+
def payout_csv(period:str, total_field:int=50000):
|
| 104 |
+
conn = db(); cur = conn.cursor()
|
| 105 |
+
cur.execute("SELECT user_id, SUM(credits) FROM usage_credits WHERE period=? GROUP BY user_id", (period,))
|
| 106 |
+
rows = cur.fetchall(); conn.close()
|
| 107 |
+
total = sum(r[1] for r in rows) or 1.0
|
| 108 |
+
lines = ["recipient_address,amount_FIELD,reason,period"]
|
| 109 |
+
for user, credits in rows:
|
| 110 |
+
amt = int(round(total_field * (credits/total)))
|
| 111 |
+
lines.append(f"{user},{amt},Guide usage,{period}")
|
| 112 |
+
return "\n".join(lines)
|
| 113 |
+
|
| 114 |
+
def dao_panel_read(field_token:str):
|
| 115 |
+
out = {"dao_address": DAO_ADDRESS, "field_token": field_token or "(set FIELD_TOKEN)", "balances": {}, "notes": ""}
|
| 116 |
+
try:
|
| 117 |
+
from web3 import Web3
|
| 118 |
+
ERC20_ABI = [
|
| 119 |
+
{"constant":True,"inputs":[{"name":"a","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
| 120 |
+
{"constant":True,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"type":"function"},
|
| 121 |
+
{"constant":True,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},
|
| 122 |
+
{"constant":True,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"type":"function"}
|
| 123 |
+
]
|
| 124 |
+
w3 = Web3(Web3.HTTPProvider(ARBITRUM_RPC, request_kwargs={"timeout": 10}))
|
| 125 |
+
if not field_token:
|
| 126 |
+
out["notes"] = "Set FIELD_TOKEN to read balances."
|
| 127 |
+
return json.dumps(out, indent=2)
|
| 128 |
+
token = w3.eth.contract(address=w3.to_checksum_address(field_token), abi=ERC20_ABI)
|
| 129 |
+
dec = token.functions.decimals().call()
|
| 130 |
+
sym = token.functions.symbol().call()
|
| 131 |
+
ts = token.functions.totalSupply().call() / (10**dec)
|
| 132 |
+
bal = token.functions.balanceOf(w3.to_checksum_address(DAO_ADDRESS)).call() / (10**dec)
|
| 133 |
+
out["balances"] = {"symbol": sym, "decimals": dec, "total_supply": ts, "dao_balance": bal}
|
| 134 |
+
except Exception as e:
|
| 135 |
+
out["notes"] = f"RPC/ABI error: {e}"
|
| 136 |
+
return json.dumps(out, indent=2)
|
| 137 |
+
|
| 138 |
+
def generate_actions_from_csv(csv_text:str, token_address:str, decimals:int=18):
|
| 139 |
+
try:
|
| 140 |
+
from web3 import Web3
|
| 141 |
+
from eth_abi import encode as abi_encode
|
| 142 |
+
except Exception as e:
|
| 143 |
+
return "Missing dependency: web3/eth_abi. Ensure requirements are installed."
|
| 144 |
+
rows = list(csv.reader(io.StringIO(csv_text.strip())))
|
| 145 |
+
header = [h.strip().lower() for h in rows[0]]
|
| 146 |
+
if header[:2] != ["recipient_address","amount_field"]:
|
| 147 |
+
return "CSV must start with columns: recipient_address,amount_FIELD,..."
|
| 148 |
+
actions = []
|
| 149 |
+
selector = Web3.keccak(text="transfer(address,uint256)")[:4]
|
| 150 |
+
w3 = Web3()
|
| 151 |
+
for r in rows[1:]:
|
| 152 |
+
if not r or len(r)<2:
|
| 153 |
+
continue
|
| 154 |
+
to = w3.to_checksum_address(r[0].strip())
|
| 155 |
+
amt = int(r[1].strip())
|
| 156 |
+
wei = amt * (10**decimals)
|
| 157 |
+
data = "0x" + (selector + abi_encode(["address","uint256"], [to, wei])).hex()
|
| 158 |
+
actions.append({"to": token_address, "value": 0, "data": data})
|
| 159 |
+
return json.dumps(actions, indent=2)
|
| 160 |
+
|
| 161 |
+
SESSION_QUERIES = {}
|
| 162 |
+
def log(evt, payload):
|
| 163 |
+
try:
|
| 164 |
+
if TELEMETRY_WEBHOOK:
|
| 165 |
+
requests.post(TELEMETRY_WEBHOOK, json={"evt":evt, **payload}, timeout=5)
|
| 166 |
+
except Exception:
|
| 167 |
+
pass
|
| 168 |
+
|
| 169 |
+
def ask(user_id:str, question:str, namespace:str, premium_key:str, period:str):
|
| 170 |
+
sid = user_id or "anon"
|
| 171 |
+
count = SESSION_QUERIES.get(sid, 0)
|
| 172 |
+
if (not PREMIUM_KEY) or (premium_key != PREMIUM_KEY):
|
| 173 |
+
if count >= FREE_LIMIT:
|
| 174 |
+
return f"Free limit reached ({FREE_LIMIT}). Enter premium key.", "", ""
|
| 175 |
+
SESSION_QUERIES[sid] = count + 1
|
| 176 |
+
|
| 177 |
+
ctx = retrieve(question, namespace)
|
| 178 |
+
if not ctx:
|
| 179 |
+
return "No guides yet. Add some first.", "", ""
|
| 180 |
+
ans = synthesize_answer(question, ctx)
|
| 181 |
+
record_usage(ctx, period)
|
| 182 |
+
log("ask", {"user": sid, "ns": namespace, "period": period, "guide_ids": [c["guide_id"] for c in ctx]})
|
| 183 |
+
src = "\n".join([f"[{i+1}] {c['title']} (id {c['guide_id']}) {c['score']:.2f}" for i,c in enumerate(ctx)])
|
| 184 |
+
return ans, src, str(int(time.time()*1000))
|
| 185 |
+
|
| 186 |
+
SEED_NAMESPACE = "inneri-guides"
|
| 187 |
+
SEED_GUIDES = [
|
| 188 |
+
("seed","Prompt Clarity: 3 Moves","1) State the goal clearly.\n2) Add 1β3 constraints.\n3) Give a short example.","prompt,basics"),
|
| 189 |
+
("seed","RAG Basics: Store & Retrieve","Chunk docs, embed, retrieve, generate with citations.","rag,basics"),
|
| 190 |
+
("seed","Chunking That Works","Overlap 50β100 tokens, respect headings, avoid >1k tokens.","rag,chunking"),
|
| 191 |
+
("seed","Choosing Embedding Models","MiniLM for speed; e5/bge for quality; normalize; version.","embeddings,models"),
|
| 192 |
+
("seed","Eval Signals","Score faithfulness, relevance, actionability.","evals,quality"),
|
| 193 |
+
("seed","Langfuse Setup","Log routes, latency; attach evals; dashboard triage.","observability,langfuse"),
|
| 194 |
+
("seed","Agentic Loops","Plan β Act β Observe β Reflect; timeouts; state; kill switch.","agents,loops"),
|
| 195 |
+
("seed","FastAPI for AI","/chat, /embed, /query; rate limit; metrics; costs.","ops,api"),
|
| 196 |
+
("seed","Data Rights & Payouts","Creators own docs; track usage; split fees.","legal,economics"),
|
| 197 |
+
("seed","Safety & Scope","Refuse dangerous asks; stay in domain; red-team.","safety,policy"),
|
| 198 |
+
]
|
| 199 |
+
|
| 200 |
+
def seed_if_empty():
|
| 201 |
+
conn = db(); cur = conn.cursor()
|
| 202 |
+
cur.execute("SELECT COUNT(*) FROM guides WHERE namespace=?",(SEED_NAMESPACE,))
|
| 203 |
+
if cur.fetchone()[0]==0:
|
| 204 |
+
for o,t,tx,tg in SEED_GUIDES:
|
| 205 |
+
add_guide(o,t,tx,tg,SEED_NAMESPACE)
|
| 206 |
+
|
| 207 |
+
init_db(); seed_if_empty()
|
| 208 |
+
|
| 209 |
+
with gr.Blocks(title="Reskill the Field β Inner I Agentic AI (DAO-Wired)") as demo:
|
| 210 |
+
gr.Markdown(f"### Reskill the Field DAO β Inner I Agentic AI\nDAO: **{DAO_ADDRESS}** (Arbitrum) | Library + RAG + Payouts + Proposal Generator")
|
| 211 |
+
|
| 212 |
+
with gr.Tab("DAO Panel"):
|
| 213 |
+
token_in = gr.Textbox(label="$FIELD Token Address (ERC-20)", value=FIELD_TOKEN)
|
| 214 |
+
read_btn = gr.Button("Read DAO Balances")
|
| 215 |
+
read_out = gr.Textbox(label="DAO Balances (JSON)", lines=10)
|
| 216 |
+
read_btn.click(lambda t: dao_panel_read(t), [token_in], [read_out])
|
| 217 |
+
gr.Markdown("Treasury note: target **1,000,000 $FIELD** held. Set `FIELD_TOKEN` to verify on-chain.")
|
| 218 |
+
|
| 219 |
+
with gr.Tab("Browse Guides"):
|
| 220 |
+
ns = gr.Textbox(label="Namespace", value=SEED_NAMESPACE)
|
| 221 |
+
list_btn = gr.Button("List")
|
| 222 |
+
table = gr.Dataframe(headers=["id","owner","title","tags","created"], datatype=["number","str","str","str","str"])
|
| 223 |
+
def _list(namespace): return [[r[0],r[1],r[2],r[3],r[4]] for r in list_guides(namespace)]
|
| 224 |
+
list_btn.click(_list,[ns],[table])
|
| 225 |
+
|
| 226 |
+
with gr.Tab("Add Guide"):
|
| 227 |
+
u = gr.Textbox(label="Your Handle (wallet address preferred for payouts)", value="0xYourWallet")
|
| 228 |
+
title = gr.Textbox(label="Title", value="My New Guide")
|
| 229 |
+
tags = gr.Textbox(label="Tags", value="custom")
|
| 230 |
+
ns2 = gr.Textbox(label="Namespace", value=SEED_NAMESPACE)
|
| 231 |
+
txt = gr.Textbox(label="Guide Text", lines=10)
|
| 232 |
+
add_btn = gr.Button("Add Guide")
|
| 233 |
+
add_out = gr.Textbox(label="Result")
|
| 234 |
+
def _add(uid,title,text,tags,ns):
|
| 235 |
+
if not text.strip(): return "Add some text."
|
| 236 |
+
gid=add_guide(uid,title,text,tags,ns); return f"Added id={gid}"
|
| 237 |
+
add_btn.click(_add,[u,title,txt,tags,ns2],[add_out])
|
| 238 |
+
|
| 239 |
+
with gr.Tab("Ask (RAG) + Usage Log"):
|
| 240 |
+
u2=gr.Textbox(label="User ID (optional)", value="")
|
| 241 |
+
q=gr.Textbox(label="Question", value="How do I set up eval signals?", lines=3)
|
| 242 |
+
ns3=gr.Textbox(label="Namespace", value=SEED_NAMESPACE)
|
| 243 |
+
period=gr.Textbox(label="Period (YYYY-MM)", value="2025-09")
|
| 244 |
+
prem=gr.Textbox(label="Premium Key (optional)", value="")
|
| 245 |
+
ask_btn=gr.Button("Ask")
|
| 246 |
+
ans=gr.Textbox(label="Answer", lines=12)
|
| 247 |
+
src=gr.Textbox(label="Sources", lines=8)
|
| 248 |
+
trace=gr.Textbox(label="Trace ID")
|
| 249 |
+
ask_btn.click(lambda uid,qq,ns,per,pk: ask(uid,qq,ns,pk,per), [u2,q,ns3,period,prem],[ans,src,trace])
|
| 250 |
+
|
| 251 |
+
with gr.Tab("Payout Builder (CSV)"):
|
| 252 |
+
per=gr.Textbox(label="Period (YYYY-MM)", value="2025-09")
|
| 253 |
+
total=gr.Number(label="Total $FIELD to distribute", value=50000, precision=0)
|
| 254 |
+
build=gr.Button("Generate CSV")
|
| 255 |
+
csv_out=gr.Textbox(label="CSV Preview", lines=12)
|
| 256 |
+
build.click(lambda p,t: payout_csv(p, int(t)), [per,total],[csv_out])
|
| 257 |
+
|
| 258 |
+
with gr.Tab("Proposal Generator (Aragon Actions)"):
|
| 259 |
+
gr.Markdown("Paste payout CSV β get ERC-20 `transfer()` actions JSON for Aragon's Custom action.")
|
| 260 |
+
csv_in = gr.Textbox(label="Payout CSV", lines=12, value="recipient_address,amount_FIELD,reason,period\n0x0000000000000000000000000000000000000000,1000,Guide usage,2025-09")
|
| 261 |
+
token_addr = gr.Textbox(label="$FIELD Token Address", value=FIELD_TOKEN)
|
| 262 |
+
decimals = gr.Number(label="Token Decimals", value=18, precision=0)
|
| 263 |
+
gen_btn = gr.Button("Generate Actions JSON")
|
| 264 |
+
actions_out = gr.Textbox(label="Encoded Actions JSON", lines=14)
|
| 265 |
+
gen_btn.click(lambda c,t,d: generate_actions_from_csv(c,t,int(d)), [csv_in, token_addr, decimals], [actions_out])
|
| 266 |
+
|
| 267 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
gradio==4.36.1
|
| 3 |
+
sentence-transformers==2.7.0
|
| 4 |
+
numpy==1.26.4
|
| 5 |
+
requests==2.32.3
|
| 6 |
+
web3==6.19.0
|
| 7 |
+
eth-abi==5.1.0
|