Spaces:
Build error
Build error
app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from importlib.machinery import PathFinder
|
| 3 |
+
import io
|
| 4 |
+
import netrc
|
| 5 |
+
import pickle
|
| 6 |
+
import sys
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import numpy as np
|
| 9 |
+
import streamlit as st
|
| 10 |
+
# let's import sentence transformer
|
| 11 |
+
import sentence_transformers
|
| 12 |
+
import torch
|
| 13 |
+
#######################################
|
| 14 |
+
|
| 15 |
+
st.markdown(
|
| 16 |
+
f"""
|
| 17 |
+
<style>
|
| 18 |
+
.reportview-container .main .block-container{{
|
| 19 |
+
max-width: 90%;
|
| 20 |
+
padding-top: 5rem;
|
| 21 |
+
padding-right: 5rem;
|
| 22 |
+
padding-left: 5rem;
|
| 23 |
+
padding-bottom: 5rem;
|
| 24 |
+
}}
|
| 25 |
+
img{{
|
| 26 |
+
max-width:40%;
|
| 27 |
+
margin-bottom:40px;
|
| 28 |
+
}}
|
| 29 |
+
</style>
|
| 30 |
+
""",
|
| 31 |
+
unsafe_allow_html=True,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# # let's load the saved model
|
| 35 |
+
loaded_model = pickle.load(open('XpathFinder1.sav', 'rb'))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# Containers
|
| 39 |
+
header_container = st.container()
|
| 40 |
+
mod_container = st.container()
|
| 41 |
+
|
| 42 |
+
# Header
|
| 43 |
+
with header_container:
|
| 44 |
+
|
| 45 |
+
# different levels of text you can include in your app
|
| 46 |
+
st.title("Xpath Finder App")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# model container
|
| 50 |
+
with mod_container:
|
| 51 |
+
|
| 52 |
+
# collecting input from user
|
| 53 |
+
prompt = st.text_input("Enter your description below ...")
|
| 54 |
+
|
| 55 |
+
# Loading e data
|
| 56 |
+
data = (pd.read_csv("/content/SBERT_data.csv")
|
| 57 |
+
).drop(['Unnamed: 0'], axis=1)
|
| 58 |
+
|
| 59 |
+
data['prompt'] = prompt
|
| 60 |
+
data.rename(columns={'target_text': 'sentence2',
|
| 61 |
+
'prompt': 'sentence1'}, inplace=True)
|
| 62 |
+
data['sentence2'] = data['sentence2'].astype('str')
|
| 63 |
+
data['sentence1'] = data['sentence1'].astype('str')
|
| 64 |
+
|
| 65 |
+
# let's pass the input to the loaded_model with torch compiled with cuda
|
| 66 |
+
if prompt:
|
| 67 |
+
# let's get the result
|
| 68 |
+
simscore = PathFinder.predict([prompt])
|
| 69 |
+
|
| 70 |
+
from sentence_transformers import CrossEncoder
|
| 71 |
+
XpathFinder = CrossEncoder("cross-encoder/stsb-roberta-base")
|
| 72 |
+
sentence_pairs = []
|
| 73 |
+
for sentence1, sentence2 in zip(data['sentence1'], data['sentence2']):
|
| 74 |
+
sentence_pairs.append([sentence1, sentence2])
|
| 75 |
+
|
| 76 |
+
# sorting the df to get highest scoring xpath_container
|
| 77 |
+
data['SBERT CrossEncoder_Score'] = XpathFinder.predict(sentence_pairs)
|
| 78 |
+
most_acc = data.head(5)
|
| 79 |
+
# predictions
|
| 80 |
+
st.write("Highest Similarity score: ", simscore)
|
| 81 |
+
st.text("Is this one of these the Xpath you're looking for?")
|
| 82 |
+
st.write(st.write(most_acc["input_text"]))
|