Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import base64
|
3 |
-
|
|
|
4 |
|
5 |
def get_clipboard_html():
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
content = f.read()
|
8 |
b64 = base64.b64encode(content.encode()).decode()
|
9 |
return f"data:text/html;base64,{b64}"
|
@@ -19,21 +25,32 @@ def main():
|
|
19 |
|
20 |
st.write(f'<iframe src="{get_clipboard_html()}" width="100%" height="300" style="border:none"></iframe>', unsafe_allow_html=True)
|
21 |
|
22 |
-
|
23 |
-
if
|
24 |
-
st.
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
if __name__ == "__main__":
|
39 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
import streamlit_ace as ace
|
3 |
import base64
|
4 |
+
import os
|
5 |
+
import time
|
6 |
|
7 |
def get_clipboard_html():
|
8 |
+
script_path = os.path.abspath(__file__)
|
9 |
+
script_dir = os.path.dirname(script_path)
|
10 |
+
clipboard_path = os.path.join(script_dir, "clipboard.html")
|
11 |
+
|
12 |
+
with open(clipboard_path, "r") as f:
|
13 |
content = f.read()
|
14 |
b64 = base64.b64encode(content.encode()).decode()
|
15 |
return f"data:text/html;base64,{b64}"
|
|
|
25 |
|
26 |
st.write(f'<iframe src="{get_clipboard_html()}" width="100%" height="300" style="border:none"></iframe>', unsafe_allow_html=True)
|
27 |
|
28 |
+
# Set up session state
|
29 |
+
if "last_clipboard" not in st.session_state:
|
30 |
+
st.session_state.last_clipboard = ""
|
31 |
+
|
32 |
+
while True:
|
33 |
+
event = st.experimental_get_query_params().get("event", [None])[0]
|
34 |
+
if event == "clipboard-update":
|
35 |
+
st.experimental_set_query_params(event="")
|
36 |
+
clipboard_text = st.experimental_get_query_params().get("data", [""])[0]
|
37 |
+
clipboard_text = base64.urlsafe_b64decode(clipboard_text).decode(errors="ignore")
|
38 |
+
|
39 |
+
if clipboard_text != st.session_state.last_clipboard:
|
40 |
+
st.session_state.last_clipboard = clipboard_text
|
41 |
+
clipboard_data.write(f"Clipboard Data: {clipboard_text}")
|
42 |
+
|
43 |
+
if clipboard_text.startswith("{") and clipboard_text.endswith("}"):
|
44 |
+
data_type.write("Data Type: JSON")
|
45 |
+
elif clipboard_text.startswith("<") and clipboard_text.endswith(">"):
|
46 |
+
data_type.write("Data Type: XML/HTML")
|
47 |
+
else:
|
48 |
+
data_type.write("Data Type: Plain Text")
|
49 |
+
|
50 |
+
data_contents.write(f"Data Contents: {clipboard_text}")
|
51 |
+
|
52 |
+
time.sleep(1)
|
53 |
+
st.experimental_rerun()
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
main()
|