Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import base64
|
3 |
+
from io import StringIO
|
4 |
+
|
5 |
+
def get_clipboard_html():
|
6 |
+
with open("clipboard.html", "r") as f:
|
7 |
+
content = f.read()
|
8 |
+
b64 = base64.b64encode(content.encode()).decode()
|
9 |
+
return f"data:text/html;base64,{b64}"
|
10 |
+
|
11 |
+
def main():
|
12 |
+
st.title("Clipboard Monitor")
|
13 |
+
|
14 |
+
st.write("Paste your data in the input box below:")
|
15 |
+
|
16 |
+
clipboard_data = st.empty()
|
17 |
+
data_type = st.empty()
|
18 |
+
data_contents = st.empty()
|
19 |
+
|
20 |
+
st.write(f'<iframe src="{get_clipboard_html()}" width="100%" height="300" style="border:none"></iframe>', unsafe_allow_html=True)
|
21 |
+
|
22 |
+
event = st.experimental_get_query_params().get("event", [None])[0]
|
23 |
+
if event == "clipboard-update":
|
24 |
+
st.experimental_set_query_params(event="")
|
25 |
+
clipboard_text = st.experimental_get_query_params().get("data", [""])[0]
|
26 |
+
clipboard_text = base64.urlsafe_b64decode(clipboard_text).decode(errors="ignore")
|
27 |
+
clipboard_data.write(f"Clipboard Data: {clipboard_text}")
|
28 |
+
|
29 |
+
if clipboard_text.startswith("{") and clipboard_text.endswith("}"):
|
30 |
+
data_type.write("Data Type: JSON")
|
31 |
+
elif clipboard_text.startswith("<") and clipboard_text.endswith(">"):
|
32 |
+
data_type.write("Data Type: XML/HTML")
|
33 |
+
else:
|
34 |
+
data_type.write("Data Type: Plain Text")
|
35 |
+
|
36 |
+
data_contents.write(f"Data Contents: {clipboard_text}")
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
main()
|