File size: 1,687 Bytes
172817d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a1f8eb
172817d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79e65e0
e284278
172817d
e284278
172817d
 
 
 
e284278
172817d
 
1
2
3
4
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
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import re
import json

# Function to parse SQL file content
def parse_sql_content(sql_lines):
    parsed_data = []
    insert_regex = re.compile(r"INSERT INTO `.*` \(`id`,`question`,`answer`,`explanation`\) VALUES \((\d+),\'(.+?)\',\'(.+?)\',\'(.+?)\'\);")

    for line in sql_lines:
        match = insert_regex.match(line)
        if match:
            answer_json = match.group(3).replace("\\", "").replace("'", '"')
            try:
                answer_data = json.loads(answer_json)
            except json.JSONDecodeError:
                answer_data = answer_json
            data = {
                "id": int(match.group(1)),
                "question": match.group(2),
                "answer": answer_data,
                "explanation": match.group(4)
            }
            parsed_data.append(data)
    return parsed_data

# Streamlit UI
st.title("SQL Content Viewer")

# File uploader
uploaded_file = st.file_uploader("Upload your SQL file", type="sql")
if uploaded_file is not None:
    sql_content = uploaded_file.getvalue().decode("utf-8").split("\n")

    # Parse SQL content
    parsed_data = parse_sql_content(sql_content)

    # Display content
    for entry in parsed_data:
        st.markdown(f"# ID: {entry['id']}")
        st.markdown("### Question")
        st.markdown(entry['question'], unsafe_allow_html=True)
        st.markdown("### Answer")
        try:
            st.write(json.dumps(entry['answer'], indent=4))
        except:
            st.markdown(entry['answer'], unsafe_allow_html=True)
        st.markdown("### Explanation")
        st.markdown(entry['explanation'], unsafe_allow_html=True)  # Display HTML content