VasudevAdhikari commited on
Commit ·
83afbd5
1
Parent(s): 51a55dc
Modify app.py without typehints to avoid errors
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
from transformers import (
|
|
@@ -25,19 +24,24 @@ sentiment_model.eval()
|
|
| 25 |
|
| 26 |
|
| 27 |
# ==============================
|
| 28 |
-
# CORE FUNCTION
|
|
|
|
|
|
|
| 29 |
# ==============================
|
| 30 |
|
| 31 |
def nlp_encode_sentence(values):
|
| 32 |
|
| 33 |
-
# values will be list of lists
|
| 34 |
-
df = pd.DataFrame(values, columns=["value"])
|
| 35 |
-
|
| 36 |
feature_rows = []
|
| 37 |
|
| 38 |
-
for
|
|
|
|
| 39 |
|
| 40 |
-
inputs = tokenizer(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
with torch.no_grad():
|
| 43 |
outputs = bert_model(**inputs)
|
|
@@ -76,7 +80,7 @@ def nlp_encode_sentence(values):
|
|
| 76 |
|
| 77 |
|
| 78 |
# ==============================
|
| 79 |
-
# GRADIO APP
|
| 80 |
# ==============================
|
| 81 |
|
| 82 |
with gr.Blocks() as demo:
|
|
@@ -109,4 +113,4 @@ with gr.Blocks() as demo:
|
|
| 109 |
)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import torch
|
| 4 |
from transformers import (
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
# ==============================
|
| 27 |
+
# CORE FUNCTION (NO PANDAS)
|
| 28 |
+
# Input: list of lists
|
| 29 |
+
# Output: list of lists
|
| 30 |
# ==============================
|
| 31 |
|
| 32 |
def nlp_encode_sentence(values):
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
feature_rows = []
|
| 35 |
|
| 36 |
+
for row in values:
|
| 37 |
+
sentence = row[0] # first column
|
| 38 |
|
| 39 |
+
inputs = tokenizer(
|
| 40 |
+
sentence,
|
| 41 |
+
return_tensors="pt",
|
| 42 |
+
truncation=True,
|
| 43 |
+
padding=True
|
| 44 |
+
)
|
| 45 |
|
| 46 |
with torch.no_grad():
|
| 47 |
outputs = bert_model(**inputs)
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
# ==============================
|
| 83 |
+
# GRADIO APP
|
| 84 |
# ==============================
|
| 85 |
|
| 86 |
with gr.Blocks() as demo:
|
|
|
|
| 113 |
)
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
+
demo.launch()
|