|
from flask import Flask, request |
|
from torch import cuda |
|
import torch |
|
import gradio as gr |
|
import pdfplumber |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
def upload_file(file): |
|
|
|
if file: |
|
pdf_file = file.name |
|
text = "" |
|
with pdfplumber.open(pdf_file) as pdf: |
|
cnt = 0 |
|
for page in pdf.pages: |
|
cnt+=1 |
|
text+=(page.extract_text(x_tolerance = 1)) |
|
if cnt>5: |
|
break |
|
text = text.replace('\n', ' ') |
|
return {"text": text} |
|
else: |
|
return {"error":'No PDF file found in request'} |
|
|
|
|
|
demo = gr.Interface( |
|
fn=upload_file, |
|
inputs=gr.File(), |
|
article = "Implemented in <a href = \"https://ai-content-detector.online/\">AI Content Detector</a>", |
|
outputs=gr.outputs.JSON(), |
|
interpretation="default",) |
|
|
|
demo.launch(show_api=False) |