File size: 2,707 Bytes
c2f1466 cf7a07e 5aca742 b0d9242 a7feab8 7192ffe da9b438 c2f1466 8c634b2 e380b26 8c634b2 c5667e0 8c634b2 8089a36 8c634b2 d7b2553 8c634b2 d7b2553 8c634b2 c2f1466 dd9b8ae 8c634b2 e380b26 925b4b9 e380b26 8c634b2 2a1d68d 8c634b2 c5667e0 e380b26 5be15aa d79f686 b30a539 5be15aa 8c634b2 d7b2553 c5667e0 8c634b2 c5667e0 8c634b2 c5667e0 5be15aa 8c634b2 dd9b8ae 8c634b2 e380b26 8c634b2 1979413 8c634b2 |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import gradio as gr
from gradio import routes
from typing import List, Type
import requests, os, re, asyncio, queue
import math
import time
import datetime
import requests, json
loop = asyncio.get_event_loop()
# Monkey patch
def get_types(cls_set: List[Type], component: str):
docset = []
types = []
if component == "input":
for cls in cls_set:
doc = inspect.getdoc(cls)
doc_lines = doc.split("\n")
docset.append(doc_lines[1].split(":")[-1])
types.append(doc_lines[1].split(")")[0].split("(")[-1])
else:
for cls in cls_set:
doc = inspect.getdoc(cls)
doc_lines = doc.split("\n")
docset.append(doc_lines[-1].split(":")[-1])
types.append(doc_lines[-1].split(")")[0].split("(")[-1])
return docset, types
routes.get_types = get_types
user_data = dict()
live_user = dict()
chat_history = []
def register(id, pw):
if not id in user_data:
user_data[id] = pw
return "ok"
else:
return "fail"
def login(id, pw):
if not id in user_data:
return "fail"
else:
if user_data[id] != pw:
return "fail"
else:
live_user[id] = 20
return "ok"
def chat(name, text, time):
if not name in user_data:
return "no id"
else:
chat_history.append({"name": name, "text":text, "time":time})
return "ok"
def get_data(name):
global live_user
for u in live_user.keys():
if u == name:
live_user[u] = 20
else:
live_user[u] -= 1
if live_user[u] < 0:
del live_user[u]
return chat_history
def get_live_user():
return live_user.keys()
def clear_data():
global chat_history
chat_history = []
return "ok"
with gr.Blocks() as demo:
count = 0
gr.Markdown(
f"{chat_history}"
)
aa = gr.Interface(
fn=chat,
inputs=["text", "text", "text"],
outputs="text",
description="chat",
)
bb = gr.Interface(
fn=login,
inputs=["text", "text"],
outputs="text",
description="login",
)
cc = gr.Interface(
fn=register,
inputs=["text", "text"],
outputs="text",
description="register",
)
dd = gr.Interface(
fn=get_data,
inputs=["text"],
outputs="text",
description="get_data",
)
gg = gr.Interface(
fn=get_live_user,
inputs=[],
outputs="text",
description="get_live_user",
)
ss = gr.Interface(
fn=clear_data,
inputs=[],
outputs="text",
description="clear_data",
)
demo.queue(max_size=32).launch() |