Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,66 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
from
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
from transformers import AutoTokenizer, AutoModel
|
4 |
+
|
5 |
+
# Load SciBERT pre-trained model and tokenizer
|
6 |
+
model_name = "allenai/scibert_scivocab_uncased"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModel.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def calculate_similarity(claim, document):
|
11 |
+
# Tokenize claim and document
|
12 |
+
inputs = tokenizer.encode_plus(claim, document, return_tensors='pt', padding=True, truncation=True)
|
13 |
+
|
14 |
+
# Generate embeddings for claim and document
|
15 |
+
with torch.no_grad():
|
16 |
+
claim_embeddings = model(**inputs)['pooler_output']
|
17 |
+
|
18 |
+
# Compute cosine similarity between embeddings
|
19 |
+
similarity = torch.cosine_similarity(claim_embeddings, document_embeddings).item()
|
20 |
+
|
21 |
+
return similarity
|
22 |
+
|
23 |
+
def search_papers(user_input):
|
24 |
+
# Implement your code to fetch search results from the desired source (e.g., arXiv, Semantic Scholar)
|
25 |
+
# ...
|
26 |
+
|
27 |
+
# For the purpose of this example, we'll use dummy data
|
28 |
+
search_results = [
|
29 |
+
{
|
30 |
+
'title': 'Paper 1 Title',
|
31 |
+
'abstract': 'Paper 1 Abstract',
|
32 |
+
'authors': ['Author 1', 'Author 2'],
|
33 |
+
'url': 'https://example.com/paper1'
|
34 |
+
},
|
35 |
+
{
|
36 |
+
'title': 'Paper 2 Title',
|
37 |
+
'abstract': 'Paper 2 Abstract',
|
38 |
+
'authors': ['Author 3', 'Author 4'],
|
39 |
+
'url': 'https://example.com/paper2'
|
40 |
+
},
|
41 |
+
{
|
42 |
+
'title': 'Paper 3 Title',
|
43 |
+
'abstract': 'Paper 3 Abstract',
|
44 |
+
'authors': ['Author 5', 'Author 6'],
|
45 |
+
'url': 'https://example.com/paper3'
|
46 |
+
}
|
47 |
+
]
|
48 |
+
|
49 |
+
return search_results
|
50 |
+
|
51 |
+
st.title('The Substantiator')
|
52 |
+
|
53 |
+
user_input = st.text_input('Input your claim')
|
54 |
+
|
55 |
+
if st.button('Substantiate'):
|
56 |
+
search_results = search_papers(user_input)
|
57 |
+
if search_results is not None and len(search_results) > 0:
|
58 |
+
for result in search_results:
|
59 |
+
st.write(result["title"])
|
60 |
+
st.write(result["abstract"])
|
61 |
+
st.write("Authors: ", ", ".join(result["authors"]))
|
62 |
+
similarity = calculate_similarity(user_input, result["abstract"])
|
63 |
+
st.write("Similarity Score: ", similarity)
|
64 |
+
st.write("-----")
|
65 |
+
else:
|
66 |
+
st.write("No results found.")
|