File size: 1,763 Bytes
98c28c1
 
f8dca5c
98c28c1
 
 
 
 
 
 
 
 
dca23cf
3027807
dca23cf
 
98c28c1
 
7c42e93
98c28c1
 
 
 
7c42e93
5424919
dca23cf
 
98c28c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import openai
from api_usage import check_gpt4_availability, get_subscription, check_key_availability #, get_usage

def get_key_info(key):
    # Return a dictionary containing key information
    openai.api_key = key
    key_avai = check_key_availability()
    info_dict = {"account_name": "",
                 "key_availability": key_avai,
                 "gpt4_availability": "",
                 "has_payment_method": "",
#                 "used": "",
                 "plan": "",
                 "soft_limit": "",
                 "hard_limit": ""}
    if key_avai:
        info = get_subscription(key)
#        used = get_usage(key)
        gpt4_avai = check_gpt4_availability()
        info_dict["account_name"] = info["account_name"]
        info_dict["gpt4_availability"] = gpt4_avai
        info_dict["has_payment_method"] = info["has_payment_method"]
#        info_dict["used"] = used
        info_dict["plan"] = info["plan"]
        info_dict["soft_limit"] = info["soft_limit_usd"]
        info_dict["hard_limit"] = info["hard_limit_usd"]
    return info_dict


def clear_inputs(text):
    return ""

with gr.Blocks() as demo:
    gr.Markdown('''
    # OpenAI API Key Status Checker
    ''')

    with gr.Row():
        with gr.Column():
            key =  gr.Textbox(lines=1, max_lines=1, label="OpenAI API Key")
            with gr.Row():
                clear_button = gr.Button("Clear")
                submit_button = gr.Button("Submit", variant="primary")
        with gr.Column():
            info = gr.JSON(label="OpenAI API Key Information")

    clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
    submit_button.click(fn=get_key_info, inputs=[key], outputs=[info], api_name="get_key_info")
demo.launch()