Team Ai
Apppublic

CerebryAi/SQL_FILE_RENDERING_TOOL

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py51 linesDownload Raw Back to root
1import streamlit as st2import re3import json4 5# Function to parse SQL file content6def 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 = answer_json18            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_data26 27# Streamlit UI28st.title("SQL Content Viewer")29 30# File uploader31uploaded_file = st.file_uploader("Upload your SQL file", type="sql")32if uploaded_file is not None:33    sql_content = uploaded_file.getvalue().decode("utf-8").split("\n")34 35    # Parse SQL content36    parsed_data = parse_sql_content(sql_content)37 38    # Display content39    for entry in parsed_data:40        st.markdown(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 content50 51