Spaces:
Runtime error
Runtime error
Commit ·
a684c95
1
Parent(s): 3a64d2e
test: fixing app
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from spacy.symbols import ORTH
|
|
| 14 |
# for listing tags from binary sequence
|
| 15 |
from itertools import compress
|
| 16 |
|
| 17 |
-
#---------------------------------------
|
| 18 |
|
| 19 |
# Loading files
|
| 20 |
path = './trained_models/'
|
|
@@ -27,10 +27,7 @@ clf = load(path + filename_model)
|
|
| 27 |
# Loading scaler
|
| 28 |
scaler = load(path + filename_scaler)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
# Parameters
|
| 33 |
-
|
| 34 |
thresh = 0.4
|
| 35 |
tag_list = ['c#',
|
| 36 |
'java',
|
|
@@ -71,10 +68,20 @@ tag_list = ['c#',
|
|
| 71 |
'c++11',
|
| 72 |
'django']
|
| 73 |
|
| 74 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
#
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def remove_code(text):
|
| 79 |
"""
|
| 80 |
Removes "<code> some text </code>" from a text.
|
|
@@ -94,19 +101,6 @@ def remove_code(text):
|
|
| 94 |
|
| 95 |
return str(soup)
|
| 96 |
|
| 97 |
-
def instantiate_spacy():
|
| 98 |
-
global nlp
|
| 99 |
-
# Instantiating language model, english
|
| 100 |
-
nlp = spacy.load("en_core_web_sm")
|
| 101 |
-
|
| 102 |
-
def import_stopwords():
|
| 103 |
-
# Importing stopwords
|
| 104 |
-
with open('./stopwords/stopwords.txt') as file:
|
| 105 |
-
my_stopwords = {line.rstrip() for line in file}
|
| 106 |
-
|
| 107 |
-
# Adding my_stopwords to spacy stopwords
|
| 108 |
-
nlp.Defaults.stop_words = nlp.Defaults.stop_words.union(my_stopwords)
|
| 109 |
-
|
| 110 |
def clean(text,tokenize=False,strict=False, **kwargs):
|
| 111 |
"""
|
| 112 |
Returns a dictionnary with keys 'text' or 'tokens', where
|
|
@@ -216,7 +210,6 @@ def my_pred(X):
|
|
| 216 |
|
| 217 |
return y_pred
|
| 218 |
|
| 219 |
-
|
| 220 |
def binary_to_tag_list(binary):
|
| 221 |
"""
|
| 222 |
Converts a binary list to the list of tags (str).
|
|
@@ -244,21 +237,18 @@ def tag_suggestion(raw_text):
|
|
| 244 |
|
| 245 |
# --------------------------------------------------
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
# Import and insantiate embedding model
|
| 254 |
-
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
| 255 |
-
|
| 256 |
-
# --------------------------------------------------
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
|
| 263 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 264 |
-
iface.launch()
|
|
|
|
| 14 |
# for listing tags from binary sequence
|
| 15 |
from itertools import compress
|
| 16 |
|
| 17 |
+
#------------------------------------------
|
| 18 |
|
| 19 |
# Loading files
|
| 20 |
path = './trained_models/'
|
|
|
|
| 27 |
# Loading scaler
|
| 28 |
scaler = load(path + filename_scaler)
|
| 29 |
|
| 30 |
+
# Defining parameters
|
|
|
|
|
|
|
|
|
|
| 31 |
thresh = 0.4
|
| 32 |
tag_list = ['c#',
|
| 33 |
'java',
|
|
|
|
| 68 |
'c++11',
|
| 69 |
'django']
|
| 70 |
|
| 71 |
+
# Instantiating language model, english
|
| 72 |
+
nlp = spacy.load("en_core_web_sm")
|
| 73 |
+
|
| 74 |
+
# Importing stopwords
|
| 75 |
+
with open('./stopwords/stopwords.txt') as file:
|
| 76 |
+
my_stopwords = {line.rstrip() for line in file}
|
| 77 |
|
| 78 |
+
# Adding my_stopwords to spacy stopwords
|
| 79 |
+
nlp.Defaults.stop_words = nlp.Defaults.stop_words.union(my_stopwords)
|
| 80 |
|
| 81 |
+
# Import and insantiate embedding model
|
| 82 |
+
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
| 83 |
+
|
| 84 |
+
# Function definitions
|
| 85 |
def remove_code(text):
|
| 86 |
"""
|
| 87 |
Removes "<code> some text </code>" from a text.
|
|
|
|
| 101 |
|
| 102 |
return str(soup)
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
def clean(text,tokenize=False,strict=False, **kwargs):
|
| 105 |
"""
|
| 106 |
Returns a dictionnary with keys 'text' or 'tokens', where
|
|
|
|
| 210 |
|
| 211 |
return y_pred
|
| 212 |
|
|
|
|
| 213 |
def binary_to_tag_list(binary):
|
| 214 |
"""
|
| 215 |
Converts a binary list to the list of tags (str).
|
|
|
|
| 237 |
|
| 238 |
# --------------------------------------------------
|
| 239 |
|
| 240 |
+
examples = [
|
| 241 |
+
["Jquery/Javascript Opacity animation with scroll <p>I'm looking to change the opacity on an object (and have the transition be animated) based on a users scroll.\nexample(http://davegamache.com/)</p>\n\n<p>I've searched everywhere\nlike here, but it ends up pointing me to the waypoints plugin (http://stackoverflow.com/questions/6316757/opacity-based-on-scroll-position)</p>\n\n<p>I've implemented the [waypoints][1] plugin and have the object fading once it's higher than 100px. [Using the offet attribute] but would like to basically control the opacity of an object and have the animation be visible like the above example.</p>\n\n<p>I've searched all over- this is my last resort.\nAny help is greatly appreciated.</p>\n"],
|
| 242 |
+
['Setting cross-domain cookies in Safari <p>I have to call domain A.com (which sets the cookies with http) from domain B.com.\nAll I do on domain B.com is (javascript): </p>\n\n<pre><code>var head = document.getElementsByTagName("head")[0];\nvar script = document.createElement("script");\nscript.src = "A.com/setCookie?cache=1231213123";\nhead.appendChild(script);\n</code></pre>\n\n<p>This sets the cookie on A.com on every browser I\'ve tested, except Safari.\nAmazingly this works in IE6, even without the P3P headers.</p>\n\n<p>Is there any way to make this work in Safari?</p>\n'],
|
| 243 |
+
['Database migrations for SQL Server <p>I need a database migration framework for SQL Server, capable of managing both schema changes and data migrations.</p>\n\n<p>I guess I am looking for something similar to django\'s <a href="http://south.aeracode.org/" rel="noreferrer">South</a> framework here.</p>\n\n<p>Given the fact that South is tightly coupled with django\'s ORM, and the fact that there\'s so many ORMs for SQL Server I guess having just a generic migration framework, enabling you to write and execute in controlled and sequential manner SQL data/schema change scripts should be sufficient.</p>\n'],
|
| 244 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
demo = gr.Interface(fn=tag_suggestion,
|
| 247 |
+
inputs="text",
|
| 248 |
+
outputs=["text"],
|
| 249 |
+
examples=examples)
|
| 250 |
|
| 251 |
|
| 252 |
+
if __name__ == "__main__":
|
| 253 |
+
demo.launch()
|
| 254 |
|
|
|
|
|
|