docverifyrag / app.py
Carlos Salgado
try to fix app bug
cdb3fec
raw
history blame
1.71 kB
import os
import io
import os
import streamlit as st
import tempfile
from scripts import analyze_metadata, generate_metadata, ingest, MODEL_NAME
st.title('# DocVerifyRAG')
st.write('## Anomaly detection for BIM document metadata')
def suggest_metadata(file_upload):
extension = uploaded_file.name.split('.')[-1]
with tempfile.NamedTemporaryFile(delete=False) as tmp:
tmp.write(uploaded_file.read())
file_path = f'{tmp.name}.{extension}'
st.write(f'Created temporary file {file_path}')
st.write('## Processing file with Unstructured')
docs = ingest(file_path)
metadata = generate_metadata(docs)
st.write('## Querying Together.ai API')
form = st.form(key='generate_form')
st.write(f'## Suggested Metadata Generated by {MODEL_NAME}')
st.write(f'### {metadata}')
with st.form('analyze_form'):
st.write('Enter your file metadata in the following schema:')
text = st.text_input(label='Filename, Description, Discipline',
value="", placeholder=str)
submitted = st.form_submit_button('Submit')
if submitted:
filename, description, discipline = text.split(',')
st.write('## Analyzing with Vectara + together.ai')
analysis = analyze_metadata(filename, description, discipline)
st.write(analysis)
st.write('## Generate metadata?')
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf","txt"])
if uploaded_file is not None:
suggest_metadata(uploaded_file)
delete_file_button = form.form_submit_button(label='Delete file')
if delete_file_button:
os.remove(file_path)