Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ tokenizer = RobertaTokenizer.from_pretrained(model_name, map_location=torch.devi
|
|
| 15 |
|
| 16 |
# function to break text into an array of sentences
|
| 17 |
def text_to_sentences(text):
|
|
|
|
| 18 |
return re.split(r'[.!?]', text)
|
| 19 |
|
| 20 |
# function to concatenate sentences into chunks of size 600 or less
|
|
@@ -59,6 +60,25 @@ def findRealProb(text):
|
|
| 59 |
realProb = ans/len(text)
|
| 60 |
return {"Real": realProb, "Fake": 1-realProb}, results
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
demo = gr.Interface(
|
| 63 |
fn=findRealProb,
|
| 64 |
inputs=gr.Textbox(placeholder="Copy and paste here..."),
|
|
|
|
| 15 |
|
| 16 |
# function to break text into an array of sentences
|
| 17 |
def text_to_sentences(text):
|
| 18 |
+
re.sub(r'(?<=[.!?])(?=[^\s])', r' ', text)
|
| 19 |
return re.split(r'[.!?]', text)
|
| 20 |
|
| 21 |
# function to concatenate sentences into chunks of size 600 or less
|
|
|
|
| 60 |
realProb = ans/len(text)
|
| 61 |
return {"Real": realProb, "Fake": 1-realProb}, results
|
| 62 |
|
| 63 |
+
@app.route('/upload', methods=['POST'])
|
| 64 |
+
def upload_file():
|
| 65 |
+
if 'pdfFile' in request.files:
|
| 66 |
+
pdf_file = request.files['pdfFile']
|
| 67 |
+
text = ""
|
| 68 |
+
with pdfplumber.open(pdf_file) as pdf:
|
| 69 |
+
cnt = 0
|
| 70 |
+
for page in pdf.pages:
|
| 71 |
+
cnt+=1
|
| 72 |
+
text+=(page.extract_text(x_tolerance = 1))
|
| 73 |
+
print(text)
|
| 74 |
+
if cnt>5:
|
| 75 |
+
break
|
| 76 |
+
return findRealProb(text)
|
| 77 |
+
# return jsonify({'text': text})
|
| 78 |
+
else:
|
| 79 |
+
return {"error":'No PDF file found in request'}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
demo = gr.Interface(
|
| 83 |
fn=findRealProb,
|
| 84 |
inputs=gr.Textbox(placeholder="Copy and paste here..."),
|