Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request
|
| 2 |
+
from transformers import RobertaForSequenceClassification, RobertaTokenizer, RobertaConfig
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
+
from transformers import RobertaConfig
|
| 5 |
+
from torch import cuda
|
| 6 |
+
import torch
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import os
|
| 9 |
+
import re
|
| 10 |
+
import pdfplumber
|
| 11 |
+
|
| 12 |
+
app = Flask(__name__)
|
| 13 |
+
|
| 14 |
+
# function to break text into an array of sentences
|
| 15 |
+
|
| 16 |
+
def upload_file(file):
|
| 17 |
+
|
| 18 |
+
if file:
|
| 19 |
+
pdf_file = file.name
|
| 20 |
+
text = ""
|
| 21 |
+
with pdfplumber.open(pdf_file) as pdf:
|
| 22 |
+
cnt = 0
|
| 23 |
+
for page in pdf.pages:
|
| 24 |
+
cnt+=1
|
| 25 |
+
text+=(page.extract_text(x_tolerance = 1))
|
| 26 |
+
if cnt>5:
|
| 27 |
+
break
|
| 28 |
+
text = text.replace('\n', ' ')
|
| 29 |
+
return text
|
| 30 |
+
else:
|
| 31 |
+
return {"error":'No PDF file found in request'}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
demo = gr.Interface(
|
| 35 |
+
fn=upload_file,
|
| 36 |
+
inputs=gr.File(),
|
| 37 |
+
article = "Visit <a href = \"https://ai-content-detector.online/\">AI Content Detector</a> for better user experience!",
|
| 38 |
+
outputs=gr.outputs.JSON(),
|
| 39 |
+
interpretation="default",)
|
| 40 |
+
|
| 41 |
+
demo.launch(show_api=False)
|