Asanaly commited on
Commit
7e5e08a
·
verified ·
1 Parent(s): d46966a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -28
main.py CHANGED
@@ -8,7 +8,7 @@ from pdf_reader import extract_text_from_pdf
8
 
9
  app = FastAPI()
10
 
11
- # CORS керек (frontend ↔ backend байланысы үшін)
12
  app.add_middleware(
13
  CORSMiddleware,
14
  allow_origins=["*"],
@@ -16,36 +16,13 @@ app.add_middleware(
16
  allow_headers=["*"],
17
  )
18
 
19
- # 🔥 Барлық файлдар бір папкада тұрғандықтан осылай жазылады
20
- # Script.js, styles.css, images—all served via /static/
21
  app.mount("/static", StaticFiles(directory="."), name="static")
22
 
23
-
24
- # 🔥 Root → index.html (frontend басты бет)
25
  @app.get("/")
26
  async def root():
27
  return FileResponse("index.html")
28
 
29
-
30
- # 🔥 TEXT summarization API
31
- @app.post("/summarize/text")
32
- async def summarize_text(data: dict):
33
- text = data.get("text", "")
34
- if not text.strip():
35
- return {"summary": "No text provided."}
36
-
37
- summary = generate_summary(text)
38
- return {"summary": summary}
39
-
40
-
41
- # 🔥 PDF summarization API
42
- @app.post("/summarize/pdf")
43
- async def summarize_pdf(file: UploadFile = File(...)):
44
- pdf_bytes = await file.read()
45
-
46
- text = extract_text_from_pdf(pdf_bytes)
47
- if not text.strip():
48
- return {"summary": "PDF is empty or unreadable."}
49
-
50
- summary = generate_summary(text)
51
- return {"summary": summary}
 
8
 
9
  app = FastAPI()
10
 
11
+ # CORS (frontend ↔ backend)
12
  app.add_middleware(
13
  CORSMiddleware,
14
  allow_origins=["*"],
 
16
  allow_headers=["*"],
17
  )
18
 
19
+ # Барлық файлдар бір папкада → static ретінде қосамыз
 
20
  app.mount("/static", StaticFiles(directory="."), name="static")
21
 
22
+ # Frontend main page
 
23
  @app.get("/")
24
  async def root():
25
  return FileResponse("index.html")
26
 
27
+ # TEXT summarization
28
+ @app.post("/summariz