Skip to content

Commit

Permalink
restructure app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
salgadev committed Apr 19, 2024
1 parent b5377e1 commit eecb28e
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,39 @@

from scripts import analyze_metadata, generate_metadata, ingest, MODEL_NAME


st.title('# DocVerifyRAG')
st.write('## Anomaly detection for BIM document metadata')

st.write('### Enter your file metadata in the following schema:')

user_input = st.text_input(
label='Filename, Description, Discipline',
value="", placeholder=str)
with st.form('my_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 st.button('Submit'):
try:
filename, description, discipline = user_input.split(',')
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?')
st.write('### Upload the file that corresponds to the submitted metadata')

uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf","txt"])

if uploaded_file is not None:
try:
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp:
tmp.write(uploaded_file.read())
file_path = tmp.name
st.write(f'Created temporary file {file_path}')

docs = ingest(file_path)
st.write('## Querying Together.ai API')
metadata = generate_metadata(docs)
st.write(f'## Metadata Generated by {MODEL_NAME}')
st.write(metadata)

# Clean up the temporary file
os.remove(file_path)

except Exception as e:
st.error(f'Error: {e}')
except ValueError:
st.error('Please enter 3 comma separated values')

st.write('## Generate metadata?')
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf","txt"])

if uploaded_file is not None:
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp:
tmp.write(uploaded_file.read())
file_path = tmp.name
st.write(f'Created temporary file {file_path}')

docs = ingest(file_path)
st.write('## Querying Together.ai API')
metadata = generate_metadata(docs)

form = st.form(key='my_form')
form.text_input(label=f'Suggested Metadata Generated by {MODEL_NAME}')
stop_button = form.form_submit_button(label='Submit')
print(metadata)

os.remove(file_path)

0 comments on commit eecb28e

Please sign in to comment.