Spaces:
Runtime error
Runtime error
Update app/main.py
Browse files- app/main.py +8 -42
app/main.py
CHANGED
|
@@ -1,42 +1,8 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
# خدمة تحميل الملفات
|
| 10 |
-
@app.post("/upload/")
|
| 11 |
-
async def upload_file(file: UploadFile = File(...)):
|
| 12 |
-
content = await file.read()
|
| 13 |
-
file_path = f"uploads/{file.filename}"
|
| 14 |
-
os.makedirs("uploads", exist_ok=True)
|
| 15 |
-
with open(file_path, "wb") as f:
|
| 16 |
-
f.write(content)
|
| 17 |
-
return {"filename": file.filename, "file_path": file_path}
|
| 18 |
-
|
| 19 |
-
# خدمة تلخيص النصوص
|
| 20 |
-
@app.post("/summarize/")
|
| 21 |
-
async def summarize(document: str):
|
| 22 |
-
summary = summarize_text(document)
|
| 23 |
-
return {"summary": summary}
|
| 24 |
-
|
| 25 |
-
# خدمة تفسير الصور
|
| 26 |
-
@app.post("/analyze-image/")
|
| 27 |
-
async def analyze(image: UploadFile = File(...)):
|
| 28 |
-
analysis = analyze_image(image)
|
| 29 |
-
return {"analysis": analysis}
|
| 30 |
-
|
| 31 |
-
# خدمة الإجابة على الأسئلة
|
| 32 |
-
@app.post("/answer/")
|
| 33 |
-
async def answer(question: str, document: str):
|
| 34 |
-
answer = answer_question(question, document)
|
| 35 |
-
return {"answer": answer}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# واجهة المستخدم
|
| 39 |
-
@app.get("/", response_class=HTMLResponse)
|
| 40 |
-
async def read_root():
|
| 41 |
-
with open("app/templates/index.html", "r") as file:
|
| 42 |
-
return file.read()
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from models import summarize_text, analyze_image, answer_question, generate_visualization, translate_document
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
@app.get("/")
|
| 7 |
+
def read_root():
|
| 8 |
+
return {"message": "Hello, World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|