Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +37 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,39 @@
|
|
| 1 |
-
import
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
| 1 |
+
import json
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
+
#Function to extract all values from a nested JSON
|
| 5 |
+
def extract_values(data):
|
| 6 |
+
if isinstance(data, dict):
|
| 7 |
+
for value in data.values():
|
| 8 |
+
yield from extract_values(value)
|
| 9 |
+
elif isinstance(data, list):
|
| 10 |
+
for item in data:
|
| 11 |
+
yeild from extract_values(item)
|
| 12 |
+
else:
|
| 13 |
+
yield data
|
| 14 |
+
|
| 15 |
+
#Function to comparison of two JSON
|
| 16 |
+
def comparison_json(json1, json2):
|
| 17 |
+
value1 = set(extract_values(json1))
|
| 18 |
+
value2 = set(extract_values(json2))
|
| 19 |
+
return sorted(value1.interaction(value2))
|
| 20 |
+
|
| 21 |
+
#streamlit UI
|
| 22 |
+
st.title("Json file Comparison File")
|
| 23 |
+
st.write("Upload Two JSON files to find similar values.")
|
| 24 |
+
|
| 25 |
+
file1 = st.file.uploader("Upload First JSON File", type=["json"])
|
| 26 |
+
file2 = st.file.uploader("Upload Second JSON File", type=["json"])
|
| 27 |
+
|
| 28 |
+
if file1 and file2:
|
| 29 |
+
json1 = json.load(file1)
|
| 30 |
+
json2 = json.load(file2)
|
| 31 |
+
|
| 32 |
+
matches = comparison_json(json1, json2)
|
| 33 |
+
|
| 34 |
+
if matches:
|
| 35 |
+
st.subheader("Similar values found")
|
| 36 |
+
st.table(matches)
|
| 37 |
+
else:
|
| 38 |
+
st.warning("No similar value founder")
|
| 39 |
+
|