Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import numpy as np
|
|
|
2 |
import gradio as gr
|
3 |
from imports import *
|
4 |
from huggingface_hub import login
|
@@ -51,29 +52,37 @@ def sentiment(sent: str):
|
|
51 |
batch = { k:v.to(device) for k, v in batch.items() }
|
52 |
outputs = model_topic(**batch)
|
53 |
pred_topic = list(set([topic_tags[i] for i in cvt2cls(outputs["tags"][0])]))
|
54 |
-
return str({"sentiment": pred_sent, "topic": pred_topic})
|
55 |
|
56 |
|
57 |
-
def
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
with gr.Blocks() as demo:
|
62 |
gr.Markdown("Demo projects Review Company and Resume parser phase 1.")
|
63 |
with gr.Tab("Review Company"):
|
64 |
-
text_input = gr.Textbox(label="Input sentence (
|
65 |
text_output = gr.Textbox(label="Result:")
|
66 |
text_button = gr.Button("Predict")
|
67 |
with gr.Tab("Extract infomation from resume"):
|
68 |
with gr.Row():
|
69 |
-
|
70 |
-
image_output = gr.Image()
|
71 |
image_button = gr.Button("Predict")
|
72 |
|
73 |
# with gr.Accordion("Open for More!"):
|
74 |
# gr.Markdown("Look at me...")
|
75 |
|
76 |
text_button.click(sentiment, inputs=text_input, outputs=text_output)
|
77 |
-
image_button.click(
|
78 |
|
79 |
demo.launch()
|
|
|
1 |
import numpy as np
|
2 |
+
import pdf2image
|
3 |
import gradio as gr
|
4 |
from imports import *
|
5 |
from huggingface_hub import login
|
|
|
52 |
batch = { k:v.to(device) for k, v in batch.items() }
|
53 |
outputs = model_topic(**batch)
|
54 |
pred_topic = list(set([topic_tags[i] for i in cvt2cls(outputs["tags"][0])]))
|
55 |
+
return "Sentiment: " + pred_sent + "\n" + "Topic in sentence: " + ". ".join([i.capitalize() for i in pred_topic]) # str({"sentiment": pred_sent, "topic": pred_topic})
|
56 |
|
57 |
|
58 |
+
def pdf_to_imgs(pdf):
|
59 |
+
path_to_pdf = pdf.name
|
60 |
+
|
61 |
+
# convert PDF to PIL images (one image by page)
|
62 |
+
first_page = True # we want here only the first page as image
|
63 |
+
if first_page: last_page = 1
|
64 |
+
else: last_page = None
|
65 |
+
|
66 |
+
imgs = pdf2image.convert_from_path(path_to_pdf, last_page=last_page)
|
67 |
+
return np.array(imgs[0])
|
68 |
|
69 |
|
70 |
with gr.Blocks() as demo:
|
71 |
gr.Markdown("Demo projects Review Company and Resume parser phase 1.")
|
72 |
with gr.Tab("Review Company"):
|
73 |
+
text_input = gr.Textbox(label="Input sentence (ex: Sếp tốt, bảo hiểm đóng full lương bảo hiểm cho nhân viên. Hàng năm tăng lương ổn OT không trả thêm tiền, chỉ cho ngày nghỉ và hỗ trợ ăn tối.):", placeholder="input here...")
|
74 |
text_output = gr.Textbox(label="Result:")
|
75 |
text_button = gr.Button("Predict")
|
76 |
with gr.Tab("Extract infomation from resume"):
|
77 |
with gr.Row():
|
78 |
+
file_input = gr.File(label="PDF", file_types=[".pdf"])
|
79 |
+
image_output = gr.Image(type="numpy", label="Image of the first page")
|
80 |
image_button = gr.Button("Predict")
|
81 |
|
82 |
# with gr.Accordion("Open for More!"):
|
83 |
# gr.Markdown("Look at me...")
|
84 |
|
85 |
text_button.click(sentiment, inputs=text_input, outputs=text_output)
|
86 |
+
image_button.click(pdf_to_imgs, inputs=file_input, outputs=image_output)
|
87 |
|
88 |
demo.launch()
|