|
import gradio as gr |
|
|
|
data_store = {} |
|
|
|
def manage_data(ID, password, action, meta): |
|
global data_store |
|
if action == 1: |
|
if ID in data_store: |
|
if data_store[ID]['password'] == password: |
|
return {"data": data_store[ID]['data'], "meta": "200"} |
|
else: |
|
return {"data": "", "meta": "201"} |
|
else: |
|
data_store[ID] = {'password': password, 'data': ''} |
|
return {"data": "", "meta": "199"} |
|
elif action == 2: |
|
if ID in data_store: |
|
if data_store[ID]['password'] == password: |
|
data_store[ID]['data'] = meta |
|
return {"data": "", "meta": "202"} |
|
else: |
|
return {"data": "", "meta": "201"} |
|
else: |
|
return {"data": "", "meta": "201"} |
|
else: |
|
return {"data": "", "meta": "400"} |
|
|
|
iface = gr.Interface( |
|
manage_data, |
|
inputs=[ |
|
gr.Textbox(label="ID"), |
|
gr.Textbox(label="Password"), |
|
gr.Number(label="Action"), |
|
gr.Textbox(label="Meta") |
|
], |
|
outputs=[ |
|
gr.JSON(label="Response") |
|
], |
|
title="My Page", |
|
description="Public Storage System using Hugging Face Space API" |
|
) |
|
|
|
iface.launch() |
|
|