Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- backend/__pycache__/main.cpython-313.pyc +0 -0
- backend/main.py +31 -0
- backend/models.py +0 -0
- backend/utils.py +0 -0
- frontend/index.html +17 -0
- frontend/script.js +20 -0
- frontend/style.css +0 -0
backend/__pycache__/main.cpython-313.pyc
ADDED
Binary file (1.76 kB). View file
|
|
backend/main.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, File
|
2 |
+
from pydantic import BaseModel
|
3 |
+
import fitz # pymupdf لاستخراج النصوص من PDF
|
4 |
+
import tika
|
5 |
+
from tika import parser
|
6 |
+
import os
|
7 |
+
|
8 |
+
# تهيئة Tika
|
9 |
+
tika.initVM()
|
10 |
+
|
11 |
+
# إنشاء تطبيق FastAPI
|
12 |
+
app = FastAPI()
|
13 |
+
|
14 |
+
# نموذج لرفع الملفات
|
15 |
+
class DocumentUpload(BaseModel):
|
16 |
+
filename: str
|
17 |
+
|
18 |
+
@app.get("/")
|
19 |
+
async def home():
|
20 |
+
return {"message": "AI Web App is Running!"}
|
21 |
+
|
22 |
+
# API لاستخراج النصوص من PDF
|
23 |
+
@app.post("/extract_text/")
|
24 |
+
async def extract_text(file: UploadFile = File(...)):
|
25 |
+
contents = await file.read()
|
26 |
+
with open(file.filename, "wb") as f:
|
27 |
+
f.write(contents)
|
28 |
+
|
29 |
+
parsed = parser.from_file(file.filename)
|
30 |
+
os.remove(file.filename) # حذف الملف بعد المعالجة
|
31 |
+
return {"text": parsed["content"]}
|
backend/models.py
ADDED
File without changes
|
backend/utils.py
ADDED
File without changes
|
frontend/index.html
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>AI Web App</title>
|
7 |
+
<link rel="stylesheet" href="style.css">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<h1>AI Web App</h1>
|
11 |
+
<input type="file" id="fileInput">
|
12 |
+
<button onclick="uploadFile()">Upload</button>
|
13 |
+
<pre id="output"></pre>
|
14 |
+
|
15 |
+
<script src="script.js"></script>
|
16 |
+
</body>
|
17 |
+
</html>
|
frontend/script.js
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
async function uploadFile() {
|
2 |
+
const fileInput = document.getElementById("fileInput");
|
3 |
+
const file = fileInput.files[0];
|
4 |
+
|
5 |
+
if (!file) {
|
6 |
+
alert("Please select a file first.");
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
|
10 |
+
const formData = new FormData();
|
11 |
+
formData.append("file", file);
|
12 |
+
|
13 |
+
const response = await fetch("http://127.0.0.1:8000/extract_text/", {
|
14 |
+
method: "POST",
|
15 |
+
body: formData
|
16 |
+
});
|
17 |
+
|
18 |
+
const data = await response.json();
|
19 |
+
document.getElementById("output").innerText = data.text;
|
20 |
+
}
|
frontend/style.css
ADDED
File without changes
|