File size: 935 Bytes
aa83d5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fae4f3
aa83d5b
 
 
 
 
 
 
8952b91
aa83d5b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, request
from torch import cuda
import torch
import gradio as gr
import pdfplumber

app = Flask(__name__)

# function to break text into an array of sentences

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)