Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import re
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Function to parse SQL file content
|
| 6 |
+
def parse_sql_content(sql_lines):
|
| 7 |
+
parsed_data = []
|
| 8 |
+
insert_regex = re.compile(r"INSERT INTO `.*` \(`id`,`question`,`answer`,`explanation`\) VALUES \((\d+),\'(.+?)\',\'(.+?)\',\'(.+?)\'\);")
|
| 9 |
+
|
| 10 |
+
for line in sql_lines:
|
| 11 |
+
match = insert_regex.match(line)
|
| 12 |
+
if match:
|
| 13 |
+
answer_json = match.group(3).replace("\\", "").replace("'", '"')
|
| 14 |
+
try:
|
| 15 |
+
answer_data = json.loads(answer_json)
|
| 16 |
+
except json.JSONDecodeError:
|
| 17 |
+
answer_data = f"Error parsing JSON: {answer_json}"
|
| 18 |
+
data = {
|
| 19 |
+
"id": int(match.group(1)),
|
| 20 |
+
"question": match.group(2),
|
| 21 |
+
"answer": answer_data,
|
| 22 |
+
"explanation": match.group(4)
|
| 23 |
+
}
|
| 24 |
+
parsed_data.append(data)
|
| 25 |
+
return parsed_data
|
| 26 |
+
|
| 27 |
+
# Streamlit UI
|
| 28 |
+
st.title("SQL Content Viewer")
|
| 29 |
+
|
| 30 |
+
# File uploader
|
| 31 |
+
uploaded_file = st.file_uploader("Upload your SQL file", type="sql")
|
| 32 |
+
if uploaded_file is not None:
|
| 33 |
+
sql_content = uploaded_file.getvalue().decode("utf-8").split("\n")
|
| 34 |
+
|
| 35 |
+
# Parse SQL content
|
| 36 |
+
parsed_data = parse_sql_content(sql_content)
|
| 37 |
+
|
| 38 |
+
# Display content
|
| 39 |
+
for entry in parsed_data:
|
| 40 |
+
st.subheader(f"ID: {entry['id']}")
|
| 41 |
+
st.markdown("## Question")
|
| 42 |
+
st.markdown(entry['question'], unsafe_allow_html=True)
|
| 43 |
+
st.markdown("## Answer")
|
| 44 |
+
try:
|
| 45 |
+
st.write(json.dumps(entry['answer'], indent=4))
|
| 46 |
+
except:
|
| 47 |
+
st.markdown(entry['answer'], unsafe_allow_html=True)
|
| 48 |
+
st.markdown("## Explanation")
|
| 49 |
+
st.markdown(entry['explanation'], unsafe_allow_html=True) # Display HTML content
|
| 50 |
+
|