Heiko Hotz commited on
Commit
2639906
1 Parent(s): c0c151c

initial commit

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -74,7 +74,8 @@ with open('data/'+contracts_files[idx]) as f:
74
  contract_data = f.read()
75
 
76
  # upload contract
77
- user_upload = st.sidebar.file_uploader('Please upload your own', type=['docx', 'pdf', 'txt'], accept_multiple_files=False)
 
78
  print(user_upload)
79
 
80
  # process upload
@@ -130,17 +131,8 @@ if st.button('Analyze'):
130
  if (not len(paragraph)==0) and not (len(question)==0):
131
  print('getting predictions')
132
  with st.spinner(text='Analysis in progress...'):
133
- #predictions = run_prediction([question], paragraph, '../models/roberta-base/')
134
- data = {}
135
- data['question'] = [question]
136
- data['context'] = paragraph
137
- print(data)
138
-
139
- predictions = run_prediction(data['question'], data['context'], 'akdeniz27/roberta-base-cuad',
140
  n_best_size=int(number_results))
141
- # print(resp)
142
- # predictions=resp.json()
143
- # print(predictions)
144
  if predictions['0'] == "":
145
  answer = 'No answer found in document'
146
  else:
@@ -148,9 +140,9 @@ if st.button('Analyze'):
148
  answer = predictions['0']
149
  st.text_area(label="Answer", value=f"{answer}")
150
  else:
151
- f = open("nbest.json")
152
- st.success(f.readlines())
 
153
  st.success("Successfully processed contract!")
154
- st.success(question)
155
  else:
156
  st.write("Unable to call model, please select question and contract")
 
74
  contract_data = f.read()
75
 
76
  # upload contract
77
+ user_upload = st.sidebar.file_uploader('Please upload your own', type=['docx', 'pdf', 'txt'],
78
+ accept_multiple_files=False)
79
  print(user_upload)
80
 
81
  # process upload
 
131
  if (not len(paragraph)==0) and not (len(question)==0):
132
  print('getting predictions')
133
  with st.spinner(text='Analysis in progress...'):
134
+ predictions = run_prediction([question], paragraph, 'akdeniz27/roberta-base-cuad',
 
 
 
 
 
 
135
  n_best_size=int(number_results))
 
 
 
136
  if predictions['0'] == "":
137
  answer = 'No answer found in document'
138
  else:
 
140
  answer = predictions['0']
141
  st.text_area(label="Answer", value=f"{answer}")
142
  else:
143
+ with open("nbest.json") as jf:
144
+ data = json.load(jf)
145
+ st.success(data["0"])
146
  st.success("Successfully processed contract!")
 
147
  else:
148
  st.write("Unable to call model, please select question and contract")