lvwerra HF Staff commited on
Commit
7348730
·
1 Parent(s): cdd62d5

first prototype

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from e2b_desktop import Sandbox
4
+
5
+
6
+ E2B_API_KEY = os.environ["E2B_API_KEY"]
7
+ DEFAULT_MAX_TOKENS = 512
8
+ SANDBOXES = {}
9
+ TMP_DIR = './tmp/'
10
+ if not os.path.exists(TMP_DIR):
11
+ os.makedirs(TMP_DIR)
12
+
13
+
14
+ custom_css = """
15
+ /* Outer wrapper to handle centering without scrolling */
16
+ .sandbox-outer-wrapper {
17
+ display: flex;
18
+ justify-content: center;
19
+ width: 100%;
20
+ padding: 20px 0;
21
+ overflow: hidden; /* Changed from overflow-x: auto */
22
+ }
23
+
24
+ .sandbox-container {
25
+ position: relative;
26
+ width: 800px;
27
+ height: 500px;
28
+ flex-shrink: 0; /* Prevents container from shrinking */
29
+ overflow: hidden;
30
+ }
31
+
32
+ .sandbox-background {
33
+ position: absolute;
34
+ top: 0;
35
+ left: 0;
36
+ width: 100%;
37
+ height: 100%;
38
+ object-fit: cover;
39
+ }
40
+
41
+ .sandbox-iframe {
42
+ position: absolute;
43
+ top: 10%;
44
+ left: 25%;
45
+ width: 1032px;
46
+ height: 776px;
47
+ border: 4px solid #444444;
48
+ transform-origin: 0 0;
49
+ transform: scale(0.392);
50
+ }
51
+ """
52
+
53
+
54
+ def update_placeholder_text():
55
+ desktop = Sandbox(api_key=E2B_API_KEY, resolution=(1024, 768), dpi=96)
56
+ desktop.stream.start(require_auth=True)
57
+ auth_key = desktop.stream.get_auth_key()
58
+ stream_url = desktop.stream.get_url(auth_key=auth_key)
59
+
60
+ html_content = f"""
61
+ <div class="sandbox-outer-wrapper">
62
+ <div class="sandbox-container">
63
+ <img src="https://huggingface.co/datasets/lvwerra/admin/resolve/main/desktop_scaled.png" class="sandbox-background" />
64
+ <iframe
65
+ src="{stream_url}"
66
+ class="sandbox-iframe"
67
+ allowfullscreen>
68
+ </iframe>
69
+ </div>
70
+ </div>
71
+ """
72
+ return html_content
73
+
74
+ # Create a Gradio app with Blocks
75
+ with gr.Blocks(css=custom_css) as demo:
76
+ gr.HTML("""<h1 style="text-align: center">Personal Computer Assistant</h1>""")
77
+
78
+ # HTML output with simulated image and iframe
79
+ html_output = gr.HTML(
80
+ value=update_placeholder_text(),
81
+ label="Output"
82
+ )
83
+
84
+ # Text input for placeholder text
85
+ placeholder_input = gr.Textbox(
86
+ value="Find picture of cute puppies",
87
+ label="Enter your command"
88
+ )
89
+
90
+ # Update button
91
+ update_btn = gr.Button("Let's go!")
92
+
93
+ # Connect the components
94
+ update_btn.click(
95
+ fn=update_placeholder_text,
96
+ inputs=None,
97
+ outputs=[html_output]
98
+ )
99
+
100
+
101
+ # Launch the app
102
+ if __name__ == "__main__":
103
+ demo.launch()