File size: 1,239 Bytes
39bcf49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896a12e
39bcf49
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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"}  # Invalid action

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()