Spaces:
Running
Running
wjbmattingly
commited on
Commit
•
2f2cdb8
1
Parent(s):
06499d6
removed duplicate main.py
Browse files
image.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
xiit edictum a caesare augusto: ut de scribe
|
2 |
-
retur uniuersus orbis. Haec descriptio pri
|
3 |
-
ma. facta est apraeside syriae cyrino
|
4 |
-
tibant omnes: ut profiterentur singuli
|
5 |
-
in suam ciuitatem Ascendit autẽ et iosepb
|
6 |
-
agalilea deciuitate natareth. in iudacam
|
7 |
-
ciuitatem dauid quae uocatur bethleem:
|
8 |
-
Oquod esset dedomo et familia dauid.
|
9 |
-
ut proficeretuir cummarta de sponsata sibi
|
10 |
-
uxorte praegnantes. Pactum est autemcũ
|
11 |
-
essent ibi : impleti sunt dies ute pareret
|
12 |
-
t peperit filium suum primogenitũ. et
|
13 |
-
pannis eum in uoluit. et reclinacuit cum in
|
14 |
-
presepio. quia non erat eis bocus in diuerso
|
15 |
-
rio. Et pastores erant in negione eadem.
|
16 |
-
tugilantes et custodientes uigilias noctis.
|
17 |
-
supra gregem suum. Et eoce angelus dñi
|
18 |
-
stetit. iuxta illos. et claritas dicincum ful
|
19 |
-
sit illos: et timuerunt timore magno
|
20 |
-
Etdixit illis angelus. Nolite timere. Ecce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
from fastapi import FastAPI, UploadFile, File
|
2 |
-
from fastapi.responses import JSONResponse
|
3 |
-
import subprocess
|
4 |
-
import json
|
5 |
-
import os
|
6 |
-
import tempfile
|
7 |
-
import shutil
|
8 |
-
from pydantic import BaseModel
|
9 |
-
import torch
|
10 |
-
|
11 |
-
app = FastAPI()
|
12 |
-
|
13 |
-
class LineDetectionResponse(BaseModel):
|
14 |
-
lines: list
|
15 |
-
|
16 |
-
@app.post("/detect_lines", response_model=LineDetectionResponse)
|
17 |
-
async def detect_lines(file: UploadFile = File(...)):
|
18 |
-
# Check if CUDA is available
|
19 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
-
|
21 |
-
# Create a temporary directory
|
22 |
-
with tempfile.TemporaryDirectory() as temp_dir:
|
23 |
-
# Save the uploaded file
|
24 |
-
temp_file_path = os.path.join(temp_dir, file.filename)
|
25 |
-
with open(temp_file_path, "wb") as buffer:
|
26 |
-
shutil.copyfileobj(file.file, buffer)
|
27 |
-
|
28 |
-
# Set up the output JSON path
|
29 |
-
lines_json_path = os.path.join(temp_dir, "lines.json")
|
30 |
-
|
31 |
-
# Run Kraken for line detection
|
32 |
-
kraken_command = f"kraken -i {temp_file_path} {lines_json_path} segment -bl --device {device}"
|
33 |
-
subprocess.run(kraken_command, shell=True, check=True)
|
34 |
-
|
35 |
-
# Load the lines from the JSON file
|
36 |
-
with open(lines_json_path, 'r') as f:
|
37 |
-
lines_data = json.load(f)
|
38 |
-
|
39 |
-
# Return the lines data
|
40 |
-
return LineDetectionResponse(lines=lines_data['lines'])
|
41 |
-
|
42 |
-
# Optionally, you can add a root endpoint for basic information
|
43 |
-
@app.get("/")
|
44 |
-
async def root():
|
45 |
-
return {"message": "Welcome to the Kraken Line Detection API"}
|
46 |
-
|
47 |
-
# To run the app with GPU support on Hugging Face Spaces, you need to use uvicorn with the following settings:
|
48 |
-
if __name__ == "__main__":
|
49 |
-
import uvicorn
|
50 |
-
uvicorn.run(app, host="0.0.0.0", port=7860, workers=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|