Carlos Salgado commited on
Commit
eecb28e
1 Parent(s): b5377e1

restructure app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -35
app.py CHANGED
@@ -5,48 +5,39 @@ import tempfile
5
 
6
  from scripts import analyze_metadata, generate_metadata, ingest, MODEL_NAME
7
 
8
-
9
  st.title('# DocVerifyRAG')
10
  st.write('## Anomaly detection for BIM document metadata')
11
 
12
- st.write('### Enter your file metadata in the following schema:')
13
-
14
- user_input = st.text_input(
15
- label='Filename, Description, Discipline',
16
- value="", placeholder=str)
17
 
18
- if st.button('Submit'):
19
- try:
20
- filename, description, discipline = user_input.split(',')
21
 
22
  st.write('## Analyzing with Vectara + together.ai')
23
  analysis = analyze_metadata(filename, description, discipline)
24
 
25
  st.write(analysis)
26
 
27
- st.write('## Generate metadata?')
28
- st.write('### Upload the file that corresponds to the submitted metadata')
29
-
30
- uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf","txt"])
31
-
32
- if uploaded_file is not None:
33
- try:
34
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp:
35
- tmp.write(uploaded_file.read())
36
- file_path = tmp.name
37
- st.write(f'Created temporary file {file_path}')
38
-
39
- docs = ingest(file_path)
40
- st.write('## Querying Together.ai API')
41
- metadata = generate_metadata(docs)
42
- st.write(f'## Metadata Generated by {MODEL_NAME}')
43
- st.write(metadata)
44
-
45
- # Clean up the temporary file
46
- os.remove(file_path)
47
-
48
- except Exception as e:
49
- st.error(f'Error: {e}')
50
- except ValueError:
51
- st.error('Please enter 3 comma separated values')
52
-
 
5
 
6
  from scripts import analyze_metadata, generate_metadata, ingest, MODEL_NAME
7
 
 
8
  st.title('# DocVerifyRAG')
9
  st.write('## Anomaly detection for BIM document metadata')
10
 
11
+ with st.form('my_form'):
12
+ st.write('Enter your file metadata in the following schema:')
13
+ text = st.text_input(label='Filename, Description, Discipline',
14
+ value="", placeholder=str)
15
+ submitted = st.form_submit_button('Submit')
16
 
17
+ if submitted:
18
+ filename, description, discipline = text.split(',')
 
19
 
20
  st.write('## Analyzing with Vectara + together.ai')
21
  analysis = analyze_metadata(filename, description, discipline)
22
 
23
  st.write(analysis)
24
 
25
+ st.write('## Generate metadata?')
26
+ uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf","txt"])
27
+
28
+ if uploaded_file is not None:
29
+ with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp:
30
+ tmp.write(uploaded_file.read())
31
+ file_path = tmp.name
32
+ st.write(f'Created temporary file {file_path}')
33
+
34
+ docs = ingest(file_path)
35
+ st.write('## Querying Together.ai API')
36
+ metadata = generate_metadata(docs)
37
+
38
+ form = st.form(key='my_form')
39
+ form.text_input(label=f'Suggested Metadata Generated by {MODEL_NAME}')
40
+ stop_button = form.form_submit_button(label='Submit')
41
+ print(metadata)
42
+
43
+ os.remove(file_path)