Spaces:
Runtime error
Runtime error
Upload 5 files
Browse files- Dockerfile +6 -14
- main.py +36 -0
- requirements.txt +5 -9
- templates/index.html +17 -0
- templates/script.js +14 -0
Dockerfile
CHANGED
|
@@ -1,14 +1,6 @@
|
|
| 1 |
-
FROM python:3.9-slim
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
COPY requirements.txt .
|
| 8 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 9 |
-
|
| 10 |
-
# نسخ باقي الملفات
|
| 11 |
-
COPY . .
|
| 12 |
-
|
| 13 |
-
# تشغيل التطبيق
|
| 14 |
-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY requirements.txt .
|
| 4 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 5 |
+
COPY . .
|
| 6 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from fastapi.staticfiles import StaticFiles
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# ربط مجلد static للواجهة الأمامية
|
| 8 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
async def root():
|
| 12 |
+
return {"message": "Welcome to AI Web App"}
|
| 13 |
+
|
| 14 |
+
from transformers import pipeline
|
| 15 |
+
|
| 16 |
+
# تحميل نموذج لتلخيص النصوص
|
| 17 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 18 |
+
# تحميل نموذج لتفسير الصور (يمكن استبداله بـ Qwen إذا كان متاحًا)
|
| 19 |
+
image_captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 20 |
+
|
| 21 |
+
from tika import parser
|
| 22 |
+
|
| 23 |
+
@app.post("/summarize")
|
| 24 |
+
async def summarize_document(file: UploadFile = File(...)):
|
| 25 |
+
# استخراج النص من المستند
|
| 26 |
+
content = parser.from_buffer(await file.read())["content"]
|
| 27 |
+
# تلخيص النص
|
| 28 |
+
summary = summarizer(content, max_length=130, min_length=30, do_sample=False)
|
| 29 |
+
return {"summary": summary[0]["summary_text"]}
|
| 30 |
+
|
| 31 |
+
@app.post("/caption")
|
| 32 |
+
async def caption_image(file: UploadFile = File(...)):
|
| 33 |
+
# تفسير الصورة
|
| 34 |
+
caption = image_captioner(await file.read())
|
| 35 |
+
return {"caption": caption[0]["generated_text"]}
|
| 36 |
+
|
requirements.txt
CHANGED
|
@@ -1,9 +1,5 @@
|
|
| 1 |
-
fastapi
|
| 2 |
-
uvicorn
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
pandas
|
| 7 |
-
matplotlib
|
| 8 |
-
seaborn
|
| 9 |
-
pymupdf
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
+
tika
|
|
|
|
|
|
|
|
|
|
|
|
templates/index.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>AI Web App</title>
|
| 6 |
+
<link rel="stylesheet" href="/static/style.css">
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h1>AI-Powered Web App</h1>
|
| 10 |
+
<form id="upload-form" enctype="multipart/form-data">
|
| 11 |
+
<input type="file" id="file-input" name="file">
|
| 12 |
+
<button type="submit">Analyze</button>
|
| 13 |
+
</form>
|
| 14 |
+
<div id="result"></div>
|
| 15 |
+
<script src="/static/script.js"></script>
|
| 16 |
+
</body>
|
| 17 |
+
</html>
|
templates/script.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.getElementById("upload-form").addEventListener("submit", async (e) => {
|
| 2 |
+
e.preventDefault();
|
| 3 |
+
const fileInput = document.getElementById("file-input");
|
| 4 |
+
const formData = new FormData();
|
| 5 |
+
formData.append("file", fileInput.files[0]);
|
| 6 |
+
|
| 7 |
+
const endpoint = fileInput.files[0].type.startsWith("image/") ? "/caption" : "/summarize";
|
| 8 |
+
const response = await fetch(endpoint, {
|
| 9 |
+
method: "POST",
|
| 10 |
+
body: formData
|
| 11 |
+
});
|
| 12 |
+
const result = await response.json();
|
| 13 |
+
document.getElementById("result").innerText = result.summary || result.caption;
|
| 14 |
+
});
|