File size: 1,487 Bytes
b10e4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from dotenv import load_dotenv
import os

# Load biến môi trường
load_dotenv()
API_KEY = os.getenv('API_KEY', 'default_key')  # Mặc định nếu không có .env
email_list = []

def clear_input():
    return "", ""

def search_email(email_input):
    if email_input:
        email = email_input.split(';')[0]
        found = next((item for item in email_list if item['email'] == email), None)
        return f"Found: {found}" if found else "Not found"
    return "Please enter an email"

def add_items(email_input):
    if email_input:
        email, password, recovery = email_input.split(';')
        new_item = {'email': email, 'password': password, 'recovery': recovery}
        email_list.append(new_item)
        return f"Added: {new_item}, Total items: {len(email_list)}"
    return "Please enter data"

with gr.Blocks() as demo:
    with gr.Row():
        email_input = gr.Textbox(label="Enter email (format: email;password;recovery_email)", 
                              placeholder="abc@gmail.com;pass;recovery@gmail.com")
    with gr.Row():
        clear_btn = gr.Button("Xóa")
        search_btn = gr.Button("Tìm kiếm")
        add_btn = gr.Button("Nhập hàng")
    output = gr.Textbox(label="Result")

    clear_btn.click(fn=clear_input, inputs=None, outputs=[email_input, output])
    search_btn.click(fn=search_email, inputs=email_input, outputs=output)
    add_btn.click(fn=add_items, inputs=email_input, outputs=output)

demo.launch()