senel commited on
Commit
eadfa8d
·
verified ·
1 Parent(s): d054b5d

home page

Browse files
Files changed (2) hide show
  1. api.py +9 -5
  2. templates/home.html +93 -0
api.py CHANGED
@@ -3,18 +3,22 @@ import os
3
  import numpy as np
4
  from io import BytesIO
5
  from PIL import Image
6
- from fastapi import FastAPI, File, UploadFile, HTTPException
7
  import fitz
8
  import preproccess
9
  import detect_with_paddle
 
 
 
10
 
11
  app = FastAPI()
12
  current_directory = os.getcwd()
 
13
 
14
- @app.get('/')
15
- async def index():
16
- return "Welcome PaddleOCR By SENEL"
17
-
18
  @app.post("/uploadfile/")
19
  async def create_upload_file(file: UploadFile = File(...)):
20
  try:
 
3
  import numpy as np
4
  from io import BytesIO
5
  from PIL import Image
6
+ from fastapi import FastAPI, File, UploadFile, HTTPException, Request
7
  import fitz
8
  import preproccess
9
  import detect_with_paddle
10
+ from fastapi.templating import Jinja2Templates
11
+ from fastapi.responses import HTMLResponse
12
+
13
 
14
  app = FastAPI()
15
  current_directory = os.getcwd()
16
+ templates = Jinja2Templates(directory="templates")
17
 
18
+ @app.get("/", response_class=HTMLResponse)
19
+ async def read_item(request: Request):
20
+ # index.html dosyasını render et
21
+ return templates.TemplateResponse("home.html", {"request": request})
22
  @app.post("/uploadfile/")
23
  async def create_upload_file(file: UploadFile = File(...)):
24
  try:
templates/home.html ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>OCR API Usage</title>
7
+ <style>
8
+ body {
9
+ font-family: Inter, sans-serif;
10
+ margin: 0;
11
+ padding: 20px;
12
+ background: #121212;
13
+ color: white;
14
+ }
15
+ .container {
16
+ max-width: 600px;
17
+ margin: auto;
18
+ }
19
+ h1 {
20
+ text-align: center;
21
+ }
22
+ .code {
23
+ background-color: #222222;
24
+ color:#f4f4f4;
25
+ padding: 10px;
26
+ border-radius: 5px;
27
+ margin-bottom: 20px;
28
+ }
29
+ .a {
30
+
31
+ color:#4990E2;
32
+
33
+ }
34
+ </style>
35
+ </head>
36
+ <body>
37
+ <div class="container">
38
+ <h1>OCR API Usage</h1>
39
+ <p>
40
+ This API is used to recognize text in image files. Supported file formats include PDF, JPG, JPEG, and PNG. Optical character recognition (OCR) is performed using PaddleOCR.</p>
41
+ <div class="code">
42
+ <p><strong>FastAPI Docs</strong></p>
43
+ <pre>
44
+ <code>
45
+
46
+ <a class="a" href='https://senel-paddleocr-pdf.hf.space/docs/'>'https://senel-paddleocr-pdf.hf.space/docs/'</a>
47
+
48
+ </code>
49
+ </pre>
50
+ </div>
51
+
52
+ <div class="code">
53
+ <p><strong>Example CURL</strong></p>
54
+ <pre>
55
+ <code>
56
+ curl -X 'POST' \
57
+ 'https://senel-paddleocr-pdf.hf.space/uploadfile/' \
58
+ -H 'accept: application/json' \
59
+ -H 'Content-Type: multipart/form-data' \
60
+ -F 'file=@file.pdf;type=application/pdf'
61
+ </code>
62
+ </pre>
63
+ </div>
64
+ <div class="code">
65
+ <p><strong>Example Python Request</strong></p>
66
+ <pre>
67
+ <code>
68
+ import requests
69
+
70
+ # API endpoint URL
71
+ url = 'https://senel-paddleocr-pdf.hf.space/uploadfile/'
72
+
73
+ # File to be sent
74
+ files = {'file': open('file.pdf', 'rb')}
75
+ # Replace 'file.pdf' with the correct file name and path
76
+
77
+ # Make the POST request
78
+ response = requests.post(url, files=files)
79
+
80
+ # Check the response
81
+ if response.status_code == 200:
82
+ # Successful response
83
+ print("Success! OCR Result:")
84
+ print(response.json())
85
+ else:
86
+ # Error case
87
+ print("Error:", response.text)
88
+ </code>
89
+ </pre>
90
+ </div>
91
+ </div>
92
+ </body>
93
+ </html>