diamond-in commited on
Commit
b7cdbfd
Β·
verified Β·
1 Parent(s): 9d80b5f

Update ui/tabs_basic.py

Browse files
Files changed (1) hide show
  1. ui/tabs_basic.py +140 -0
ui/tabs_basic.py CHANGED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Basic feature tabs for the UI
3
+ """
4
+ import gradio as gr
5
+ from browser.actions import browse_and_extract, screenshot, click, fill, submit_form, execute_js
6
+ from browser.driver import close_persistent_driver
7
+ from features.extraction import get_html_source, save_html_to_file, get_page_info
8
+ from features.cookies import get_cookies, set_cookies
9
+ from features.advanced import wait_for_element, scroll_page, hover_element, press_key
10
+
11
+ def create_basic_tabs():
12
+ """Create tabs for basic browser features"""
13
+
14
+ with gr.Tab("πŸ” Extract Text"):
15
+ with gr.Row():
16
+ url_in = gr.Textbox(label="URL", value="https://example.com")
17
+ sel_in = gr.Textbox(label="CSS Selector", value="body")
18
+ persist_check = gr.Checkbox(label="Use Persistent Browser", value=False)
19
+ out = gr.Textbox(label="Extracted Text", lines=10)
20
+ gr.Button("Extract", variant="primary").click(
21
+ browse_and_extract, [url_in, sel_in, persist_check], out
22
+ )
23
+
24
+ with gr.Tab("πŸ“Έ Screenshot"):
25
+ with gr.Row():
26
+ url_in2 = gr.Textbox(label="URL", value="https://example.com")
27
+ full_page_check = gr.Checkbox(label="Full Page Screenshot", value=False)
28
+ persist_check2 = gr.Checkbox(label="Use Persistent Browser", value=False)
29
+ out_img = gr.Image(label="Screenshot")
30
+ gr.Button("Take Screenshot", variant="primary").click(
31
+ screenshot, [url_in2, full_page_check, persist_check2], out_img
32
+ )
33
+
34
+ with gr.Tab("πŸ‘† Click"):
35
+ with gr.Row():
36
+ url_in3 = gr.Textbox(label="URL")
37
+ sel_in3 = gr.Textbox(label="CSS Selector", placeholder="button#submit")
38
+ persist_check3 = gr.Checkbox(label="Use Persistent Browser", value=False)
39
+ out3 = gr.Textbox(label="Result", lines=4)
40
+ gr.Button("Click", variant="primary").click(
41
+ click, [url_in3, sel_in3, persist_check3], out3
42
+ )
43
+
44
+ with gr.Tab("✏️ Fill"):
45
+ with gr.Row():
46
+ url_in4 = gr.Textbox(label="URL")
47
+ sel_in4 = gr.Textbox(label="CSS Selector", placeholder="input#username")
48
+ txt_in4 = gr.Textbox(label="Text to Fill")
49
+ persist_check4 = gr.Checkbox(label="Use Persistent Browser", value=False)
50
+ out4 = gr.Textbox(label="Result", lines=2)
51
+ gr.Button("Fill", variant="primary").click(
52
+ fill, [url_in4, sel_in4, txt_in4, persist_check4], out4
53
+ )
54
+
55
+ with gr.Tab("πŸ“ Form Submit"):
56
+ with gr.Row():
57
+ url_in_form = gr.Textbox(label="URL")
58
+ persist_check_form = gr.Checkbox(label="Use Persistent Browser", value=False)
59
+ form_data_in = gr.Textbox(
60
+ label="Form Data",
61
+ placeholder="selector1:value1;selector2:value2",
62
+ lines=3,
63
+ info="Format: CSS_selector:value pairs separated by semicolons"
64
+ )
65
+ submit_btn_in = gr.Textbox(
66
+ label="Submit Button Selector (optional)",
67
+ placeholder="button[type='submit']"
68
+ )
69
+ out_form = gr.Textbox(label="Result", lines=4)
70
+ gr.Button("Submit Form", variant="primary").click(
71
+ submit_form,
72
+ [url_in_form, form_data_in, submit_btn_in, persist_check_form],
73
+ out_form
74
+ )
75
+
76
+ with gr.Tab("πŸ’» Execute JS"):
77
+ with gr.Row():
78
+ url_in5 = gr.Textbox(label="URL", value="https://example.com")
79
+ persist_check5 = gr.Checkbox(label="Use Persistent Browser", value=False)
80
+ script_in5 = gr.Textbox(
81
+ label="JavaScript Code",
82
+ lines=5,
83
+ value="return {title: document.title, url: document.URL, links: document.links.length};"
84
+ )
85
+ out5 = gr.Textbox(label="Result", lines=3)
86
+ gr.Button("Execute", variant="primary").click(
87
+ execute_js, [url_in5, script_in5, persist_check5], out5
88
+ )
89
+
90
+ with gr.Tab("πŸͺ Cookies"):
91
+ with gr.Row():
92
+ with gr.Column():
93
+ gr.Markdown("### Get Cookies")
94
+ url_in_cookies = gr.Textbox(label="URL")
95
+ persist_check_cookies = gr.Checkbox(label="Use Persistent Browser", value=False)
96
+ cookies_out = gr.Textbox(label="Cookies (JSON)", lines=10)
97
+ gr.Button("Get Cookies").click(
98
+ get_cookies, [url_in_cookies, persist_check_cookies], cookies_out
99
+ )
100
+
101
+ with gr.Column():
102
+ gr.Markdown("### Set Cookies")
103
+ url_in_set_cookies = gr.Textbox(label="URL")
104
+ cookies_in = gr.Textbox(
105
+ label="Cookies JSON",
106
+ lines=8,
107
+ placeholder='[{"name": "cookie_name", "value": "cookie_value"}]'
108
+ )
109
+ persist_check_set_cookies = gr.Checkbox(label="Use Persistent Browser", value=False)
110
+ set_cookies_out = gr.Textbox(label="Result")
111
+ gr.Button("Set Cookies").click(
112
+ set_cookies,
113
+ [url_in_set_cookies, cookies_in, persist_check_set_cookies],
114
+ set_cookies_out
115
+ )
116
+
117
+ with gr.Tab("πŸ“„ HTML Source"):
118
+ with gr.Row():
119
+ url_in_html = gr.Textbox(label="URL", value="https://example.com")
120
+ persist_check_html = gr.Checkbox(label="Use Persistent Browser", value=False)
121
+ with gr.Row():
122
+ with gr.Column():
123
+ out_html = gr.Code(label="HTML Source Code", language="html", lines=20)
124
+ gr.Button("Get HTML", variant="primary").click(
125
+ get_html_source, [url_in_html, persist_check_html], out_html
126
+ )
127
+ with gr.Column():
128
+ filename_in = gr.Textbox(label="Filename (optional)", placeholder="auto-generated")
129
+ save_out = gr.File(label="Saved HTML File")
130
+ gr.Button("Save HTML to File", variant="secondary").click(
131
+ save_html_to_file,
132
+ [url_in_html, filename_in, persist_check_html],
133
+ save_out
134
+ )
135
+
136
+ with gr.Tab("πŸ”§ Browser Control"):
137
+ close_out = gr.Textbox(label="Status")
138
+ gr.Button("Close Persistent Browser", variant="stop").click(
139
+ close_persistent_driver, [], close_out
140
+ )