stmnk commited on
Commit
02f6b9f
0 Parent(s):

Duplicate from stmnk/mlrefkws

Browse files
Files changed (3) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +39 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Mlrefkws
3
+ emoji: 💻
4
+ colorFrom: purple
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.17.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: stmnk/mlrefkws
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os; import json; import requests
2
+ import streamlit as st
3
+ ES_URL = os.environ.get("ES_URL")
4
+
5
+ question = 'What is the capital of Netherlands?'
6
+ query_text = 'Query used for keyword search (you can also edit, and experiment with the responses)'
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
18
+ }}})
19
+ headers = {'Content-Type': 'application/json'}
20
+ response = requests.request("GET", url, headers=headers, data=payload)
21
+ kws_result = response.json() # print(response.text)
22
+ # qa_result = pipe_exqa(question=question, context=paragraph)
23
+
24
+ except Exception as e:
25
+ qa_result = str(e)
26
+
27
+ top_5_hits = kws_result['hits']['hits'][:5] # print("First 5 results:")
28
+ top_5_text = [{'text': hit['_source']['content'][:500],
29
+ 'confidence': hit['_score']} for hit in top_5_hits ]
30
+
31
+ for i, doc_hit in enumerate(top_5_text):
32
+ st.subheader(f'Search result #{i+1} (and score):')
33
+ st.write(f'<em>{doc_hit["text"]}...</em>', unsafe_allow_html = True)
34
+ st.markdown(f'> (*confidence score*: **{format(doc_hit["confidence"], ".3f")}**)')
35
+
36
+ st.write(f'Answer JSON: '); st.write(top_5_text) # st.write(qa_result)
37
+ else:
38
+ st.write('Write a query to submit your keyword search'); st.stop()
39
+