Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,10 +46,6 @@ p2p_list['id'] = '11111111'
|
|
46 |
|
47 |
gpu_add_list = []
|
48 |
|
49 |
-
def chat(id, npc, prompt):
|
50 |
-
|
51 |
-
return "AI ์๋ต์
๋๋ค."
|
52 |
-
|
53 |
|
54 |
def register(id, pw):
|
55 |
if id in account_list:
|
@@ -104,11 +100,12 @@ def get_id_from_p2p(i):
|
|
104 |
# Blockchain code
|
105 |
|
106 |
|
107 |
-
|
|
|
108 |
data = requests.get("https://health.petals.dev/api/v1/state").json()
|
109 |
out = []
|
110 |
for d in data['model_reports']:
|
111 |
-
if d['name'] ==
|
112 |
for r in d['server_rows']:
|
113 |
out.append(r['peer_id'])
|
114 |
return out
|
@@ -116,13 +113,17 @@ def get_peers(name):
|
|
116 |
blockchain = Blockchain()
|
117 |
|
118 |
def add_transaction(id, kind, data):
|
119 |
-
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
def proof(
|
122 |
-
peers = get_peers(
|
123 |
for p in gpu_add_list:
|
124 |
if not p in peers:
|
125 |
-
add_transaction(get_id_from_p2p(peer), "out", 0)
|
126 |
|
127 |
def get_coin(id):
|
128 |
c = blockchain.get_user_balance(id)
|
@@ -141,6 +142,21 @@ def get_data():
|
|
141 |
|
142 |
return output
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
with gr.Blocks() as demo:
|
145 |
count = 0
|
146 |
aa = gr.Interface(
|
@@ -185,18 +201,25 @@ with gr.Blocks() as demo:
|
|
185 |
description="add_p, id๋ก p2p id ์ถ๊ฐ. ok ๋ฐํ. \n /run/predict_5",
|
186 |
)
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
gc = gr.Interface(
|
189 |
fn=get_coin,
|
190 |
inputs=["text"],
|
191 |
outputs="text",
|
192 |
-
description="get_coin, id๋ก ์์ฌ ์ฝ์ธ(ํ๋๋ ฅ) ๋ฐํ. \n /run/
|
193 |
)
|
194 |
|
195 |
gd = gr.Interface(
|
196 |
fn=get_data,
|
197 |
inputs=[],
|
198 |
outputs="text",
|
199 |
-
description="get_data, ์๊ฐํ์ฉ ๋ชจ๋ ๋ฐ์ดํฐ ๋ฐํ. gpu๊ธฐ์ฌ ๋ชฉ๋ก, total/used, chain \n /run/
|
200 |
)
|
201 |
|
202 |
demo.queue(max_size=32).launch(enable_queue=True)
|
|
|
46 |
|
47 |
gpu_add_list = []
|
48 |
|
|
|
|
|
|
|
|
|
49 |
|
50 |
def register(id, pw):
|
51 |
if id in account_list:
|
|
|
100 |
# Blockchain code
|
101 |
|
102 |
|
103 |
+
model_name = "petals-team/StableBeluga2"
|
104 |
+
def get_peers(model_name):
|
105 |
data = requests.get("https://health.petals.dev/api/v1/state").json()
|
106 |
out = []
|
107 |
for d in data['model_reports']:
|
108 |
+
if d['name'] == model_name:
|
109 |
for r in d['server_rows']:
|
110 |
out.append(r['peer_id'])
|
111 |
return out
|
|
|
113 |
blockchain = Blockchain()
|
114 |
|
115 |
def add_transaction(id, kind, data):
|
116 |
+
if kind == "add" or kind == "inference" or kind == "out":
|
117 |
+
blockchain.new_transaction(id, kind, data)
|
118 |
+
return "ok"
|
119 |
+
else:
|
120 |
+
return "fail"
|
121 |
|
122 |
+
def proof(model_name):
|
123 |
+
peers = get_peers(model_name)
|
124 |
for p in gpu_add_list:
|
125 |
if not p in peers:
|
126 |
+
add_transaction(get_id_from_p2p(peer), "out", 0)
|
127 |
|
128 |
def get_coin(id):
|
129 |
c = blockchain.get_user_balance(id)
|
|
|
142 |
|
143 |
return output
|
144 |
|
145 |
+
|
146 |
+
def chat(id, npc, prompt):
|
147 |
+
if blockchain.get_coin(id) == 0:
|
148 |
+
return "no coin"
|
149 |
+
|
150 |
+
# model inference
|
151 |
+
output = "AI ์๋ต์
๋๋ค."
|
152 |
+
add_transaction(id, "inference", {"prompt":prompt, "output":output})
|
153 |
+
|
154 |
+
if len(blockchain.current_transactions)>=10:
|
155 |
+
proof(model_name)
|
156 |
+
new_block = blockchain.new_block()
|
157 |
+
return output
|
158 |
+
|
159 |
+
|
160 |
with gr.Blocks() as demo:
|
161 |
count = 0
|
162 |
aa = gr.Interface(
|
|
|
201 |
description="add_p, id๋ก p2p id ์ถ๊ฐ. ok ๋ฐํ. \n /run/predict_5",
|
202 |
)
|
203 |
|
204 |
+
addp = gr.Interface(
|
205 |
+
fn=add_transaction,
|
206 |
+
inputs=["text", "text", "text"],
|
207 |
+
outputs="text",
|
208 |
+
description="add_transaction \n /run/predict_6",
|
209 |
+
)
|
210 |
+
|
211 |
gc = gr.Interface(
|
212 |
fn=get_coin,
|
213 |
inputs=["text"],
|
214 |
outputs="text",
|
215 |
+
description="get_coin, id๋ก ์์ฌ ์ฝ์ธ(ํ๋๋ ฅ) ๋ฐํ. \n /run/predict_7",
|
216 |
)
|
217 |
|
218 |
gd = gr.Interface(
|
219 |
fn=get_data,
|
220 |
inputs=[],
|
221 |
outputs="text",
|
222 |
+
description="get_data, ์๊ฐํ์ฉ ๋ชจ๋ ๋ฐ์ดํฐ ๋ฐํ. gpu๊ธฐ์ฌ ๋ชฉ๋ก, total/used, chain \n /run/predict_8",
|
223 |
)
|
224 |
|
225 |
demo.queue(max_size=32).launch(enable_queue=True)
|