prosekutor commited on
Commit
960672d
·
1 Parent(s): 5b84a58

interface created

Browse files
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Skimlit
3
- emoji: 💻
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
@@ -10,3 +10,5 @@ pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
  title: Skimlit
3
+ emoji: 📄🔥
4
  colorFrom: red
5
  colorTo: red
6
  sdk: gradio
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
+
14
+ Original source code can be found at https://www.github.com/harisj58/skimlit
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from keras.layers.preprocessing.text_vectorization import TextVectorization
4
+ import pandas as pd
5
+ import re, string
6
+
7
+
8
+ model_path = "skimlit_max_trained_model"
9
+
10
+
11
+ @tf.keras.utils.register_keras_serializable(package="Custom", name=None)
12
+ def custom_standardization(input_data):
13
+ lowercase = tf.strings.lower(input_data)
14
+ stripped_html = tf.strings.regex_replace(lowercase, "", " ")
15
+ return tf.strings.regex_replace(
16
+ stripped_html, "[%s]" % re.escape(string.punctuation), ""
17
+ )
18
+
19
+
20
+ model = None
21
+ with tf.keras.utils.custom_object_scope(
22
+ {"custom_standardization": custom_standardization}
23
+ ):
24
+ model = tf.keras.models.load_model(model_path) # Folder
25
+
26
+ if model is not None:
27
+ model.summary()
28
+ else:
29
+ print("Model not loaded, sorry...")
30
+
31
+ # Load saved model
32
+ loaded_model = tf.keras.models.load_model(model_path)
33
+
34
+
35
+ def get_results(abs_text):
36
+ text = ""
37
+ labels = ["BACKGROUND", "CONCLUSIONS", "METHODS", "OBJECTIVE", "RESULTS"]
38
+ sent_list = abs_text.split(sep=".")
39
+ sent_list.pop()
40
+ sent_list = [sentence.strip() for sentence in sent_list]
41
+ i = 0
42
+ total_lines = len(sent_list)
43
+ final_list = []
44
+ temp = {}
45
+ for line in sent_list:
46
+ temp["text"] = line
47
+ temp["line_number"] = i
48
+ temp["total_lines"] = total_lines
49
+ i += 1
50
+ final_list.append(temp)
51
+ temp = {}
52
+ df = pd.DataFrame(final_list)
53
+ chars = [" ".join(list(sentence)) for sentence in sent_list]
54
+ line_numbers_one_hot = tf.one_hot(df.line_number.to_numpy(), depth=15)
55
+ lines_total_one_hot = tf.one_hot(df.total_lines.to_numpy(), depth=20)
56
+ preds = tf.argmax(
57
+ loaded_model.predict(
58
+ x=(
59
+ line_numbers_one_hot,
60
+ lines_total_one_hot,
61
+ tf.constant(sent_list),
62
+ tf.constant(chars),
63
+ ),
64
+ verbose=0,
65
+ ),
66
+ axis=1,
67
+ )
68
+ i = 0
69
+ for i in range(0, total_lines):
70
+ if i != 0 and preds[i] != preds[i - 1]:
71
+ text += f"\n\n{labels[preds[i]]}: "
72
+ text += f"{sent_list[i]}."
73
+ # print(f"\n\n{labels[preds[i]]}:", end=" ")
74
+ # print(f"{sent_list[i]}.", end=" ")
75
+ elif i == 0:
76
+ text += f"{labels[preds[i]]}: "
77
+ text += f"{sent_list[i]}."
78
+ # print(f"{labels[preds[i]]}:", end=" ")
79
+ # print(f"{sent_list[i]}.", end=" ")
80
+ else:
81
+ text += f"{sent_list[i]}."
82
+ # print(f"{sent_list[i]}.", end=" ")
83
+ return text
84
+
85
+
86
+ def skimlit_analysis(text):
87
+ # print(output)
88
+ return get_results(text)
89
+
90
+
91
+ intfc = gr.Interface(
92
+ fn=skimlit_analysis,
93
+ inputs=gr.Textbox(
94
+ label="Input abstract here",
95
+ lines=2,
96
+ placeholder="Input your abstract here (the model works best with ones from medical research papers)",
97
+ ),
98
+ outputs=gr.Text(label="Skimmable Abstract", interactive=False),
99
+ )
100
+ intfc.launch()
requirements.txt ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py==1.4.0
2
+ aiofiles==23.1.0
3
+ aiohttp==3.8.4
4
+ aiosignal==1.3.1
5
+ altair==5.0.0
6
+ anyio==3.6.2
7
+ astunparse==1.6.3
8
+ async-timeout==4.0.2
9
+ attrs==23.1.0
10
+ cachetools==5.3.0
11
+ certifi==2023.5.7
12
+ charset-normalizer==3.1.0
13
+ click==8.1.3
14
+ colorama==0.4.6
15
+ contourpy==1.0.7
16
+ cycler==0.11.0
17
+ fastapi==0.95.1
18
+ ffmpy==0.3.0
19
+ filelock==3.12.0
20
+ flatbuffers==23.5.9
21
+ fonttools==4.39.4
22
+ frozenlist==1.3.3
23
+ fsspec==2023.5.0
24
+ gast==0.4.0
25
+ google-auth==2.18.0
26
+ google-auth-oauthlib==1.0.0
27
+ google-pasta==0.2.0
28
+ gradio==3.30.0
29
+ gradio_client==0.2.4
30
+ grpcio==1.54.2
31
+ h11==0.14.0
32
+ h5py==3.8.0
33
+ httpcore==0.17.0
34
+ httpx==0.24.0
35
+ huggingface-hub==0.14.1
36
+ idna==3.4
37
+ jax==0.4.10
38
+ Jinja2==3.1.2
39
+ jsonschema==4.17.3
40
+ keras==2.12.0
41
+ kiwisolver==1.4.4
42
+ libclang==16.0.0
43
+ linkify-it-py==2.0.2
44
+ Markdown==3.4.3
45
+ markdown-it-py==2.2.0
46
+ MarkupSafe==2.1.2
47
+ matplotlib==3.7.1
48
+ mdit-py-plugins==0.3.3
49
+ mdurl==0.1.2
50
+ ml-dtypes==0.1.0
51
+ multidict==6.0.4
52
+ numpy==1.23.5
53
+ oauthlib==3.2.2
54
+ opt-einsum==3.3.0
55
+ orjson==3.8.12
56
+ packaging==23.1
57
+ pandas==2.0.1
58
+ Pillow==9.5.0
59
+ protobuf==4.23.0
60
+ pyasn1==0.5.0
61
+ pyasn1-modules==0.3.0
62
+ pydantic==1.10.7
63
+ pydub==0.25.1
64
+ Pygments==2.15.1
65
+ pyparsing==3.0.9
66
+ pyrsistent==0.19.3
67
+ python-dateutil==2.8.2
68
+ python-multipart==0.0.6
69
+ pytz==2023.3
70
+ PyYAML==6.0
71
+ requests==2.30.0
72
+ requests-oauthlib==1.3.1
73
+ rsa==4.9
74
+ scipy==1.10.1
75
+ semantic-version==2.10.0
76
+ six==1.16.0
77
+ sniffio==1.3.0
78
+ starlette==0.26.1
79
+ tensorboard==2.12.3
80
+ tensorboard-data-server==0.7.0
81
+ tensorflow==2.12.0
82
+ tensorflow-estimator==2.12.0
83
+ tensorflow-intel==2.12.0
84
+ tensorflow-io-gcs-filesystem==0.31.0
85
+ termcolor==2.3.0
86
+ toolz==0.12.0
87
+ tqdm==4.65.0
88
+ typing_extensions==4.5.0
89
+ tzdata==2023.3
90
+ uc-micro-py==1.0.2
91
+ urllib3==1.26.15
92
+ uvicorn==0.22.0
93
+ websockets==11.0.3
94
+ Werkzeug==2.3.4
95
+ wrapt==1.14.1
96
+ yarl==1.9.2
skimlit_max_trained_model/keras_metadata.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f48a02c761a858c821a9d8e1916b2364a4ae0154e98ca63ba3e8cb5be12c7fa
3
+ size 35641
skimlit_max_trained_model/saved_model.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd525ae8c68fa98ba75223a708d9b948d3773af280ce68dcde070c283a4300b1
3
+ size 14956303
skimlit_max_trained_model/variables/variables.index ADDED
Binary file (16.3 kB). View file