stmnk commited on
Commit
9a946af
1 Parent(s): 836c59d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -7,11 +7,37 @@ query_text = 'Query used for keyword search (you can also edit, and experiment w
7
  written_question = st.text_input(query_text, question)
8
  if written_question:
9
  question = written_question
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  if st.button('Run keyword search'):
11
  if question:
12
  try:
13
  url = f"{ES_URL}/document/_search?pretty"
14
- # payload = json.dumps({"query":{"match":{"content":"moldova"}}})
15
  payload = json.dumps({"query": {
16
  "more_like_this": { "like": question, # "What is the capital city of Netherlands?"
17
  "fields": ["content"], "min_term_freq": 1.9, "min_doc_freq": 4, "max_query_terms": 50
 
7
  written_question = st.text_input(query_text, question)
8
  if written_question:
9
  question = written_question
10
+
11
+ if st.button('Run keyword match'):
12
+ if question:
13
+ try:
14
+ url = f"{ES_URL}/document/_search?pretty"
15
+ payload = json.dumps({"query":{"match":{"content": question}}}) # "moldova"
16
+ headers = {'Content-Type': 'application/json'}
17
+ response = requests.request("GET", url, headers=headers, data=payload)
18
+ kws_result = response.json() # print(response.text)
19
+ # qa_result = pipe_exqa(question=question, context=paragraph)
20
+
21
+ except Exception as e:
22
+ qa_result = str(e)
23
+
24
+ top_5_hits = kws_result['hits']['hits'][:5] # print("First 5 results:")
25
+ top_5_text = [{'text': hit['_source']['content'][:500],
26
+ 'confidence': hit['_score']} for hit in top_5_hits ]
27
+
28
+ for i, doc_hit in enumerate(top_5_text):
29
+ st.subheader(f'Search result #{i+1} (and score):')
30
+ st.write(f'<em>{doc_hit["text"]}...</em>', unsafe_allow_html = True)
31
+ st.markdown(f'> (*confidence score*: **{format(doc_hit["confidence"], ".3f")}**)')
32
+
33
+ st.write(f'Answer JSON: '); st.write(top_5_text) # st.write(qa_result)
34
+ else:
35
+ st.write('Write a query to submit your keyword search'); st.stop()
36
+
37
  if st.button('Run keyword search'):
38
  if question:
39
  try:
40
  url = f"{ES_URL}/document/_search?pretty"
 
41
  payload = json.dumps({"query": {
42
  "more_like_this": { "like": question, # "What is the capital city of Netherlands?"
43
  "fields": ["content"], "min_term_freq": 1.9, "min_doc_freq": 4, "max_query_terms": 50