KJ24 commited on
Commit
e97581f
·
verified ·
1 Parent(s): aec39ab

Rename main.py to app.py

Browse files
Files changed (1) hide show
  1. main.py → app.py +6 -13
main.py → app.py RENAMED
@@ -2,18 +2,18 @@ from fastapi import FastAPI, UploadFile, File
2
  from fastapi.responses import JSONResponse
3
  import os
4
  from tempfile import NamedTemporaryFile
5
- from typing import Optional
6
-
7
  from docx import Document
8
  import pdfplumber
9
- import pandas as pd
10
 
11
  app = FastAPI()
12
 
 
13
  def extract_text_from_docx(file_path):
14
  doc = Document(file_path)
15
  return "\n".join([p.text for p in doc.paragraphs])
16
 
 
17
  def extract_text_from_pdf(file_path):
18
  text = ""
19
  with pdfplumber.open(file_path) as pdf:
@@ -21,6 +21,7 @@ def extract_text_from_pdf(file_path):
21
  text += page.extract_text() + "\n"
22
  return text
23
 
 
24
  def extract_text_from_sheet(file_path):
25
  if file_path.endswith(".csv"):
26
  df = pd.read_csv(file_path)
@@ -28,6 +29,7 @@ def extract_text_from_sheet(file_path):
28
  df = pd.read_excel(file_path)
29
  return df.to_string(index=False)
30
 
 
31
  @app.post("/upload")
32
  async def upload(file: UploadFile = File(...)):
33
  extension = os.path.splitext(file.filename)[1].lower()
@@ -57,16 +59,7 @@ async def upload(file: UploadFile = File(...)):
57
  "texte": texte
58
  }
59
 
60
- # ✅ Ajoute un point de test
61
  @app.get("/")
62
  def ping():
63
  return {"message": "L'API fonctionne ✅"}
64
-
65
-
66
- import uvicorn
67
-
68
- if __name__ == "__main__":
69
- uvicorn.run("main:app", host="0.0.0.0", port=7860)
70
-
71
-
72
-
 
2
  from fastapi.responses import JSONResponse
3
  import os
4
  from tempfile import NamedTemporaryFile
5
+ import pandas as pd
 
6
  from docx import Document
7
  import pdfplumber
 
8
 
9
  app = FastAPI()
10
 
11
+
12
  def extract_text_from_docx(file_path):
13
  doc = Document(file_path)
14
  return "\n".join([p.text for p in doc.paragraphs])
15
 
16
+
17
  def extract_text_from_pdf(file_path):
18
  text = ""
19
  with pdfplumber.open(file_path) as pdf:
 
21
  text += page.extract_text() + "\n"
22
  return text
23
 
24
+
25
  def extract_text_from_sheet(file_path):
26
  if file_path.endswith(".csv"):
27
  df = pd.read_csv(file_path)
 
29
  df = pd.read_excel(file_path)
30
  return df.to_string(index=False)
31
 
32
+
33
  @app.post("/upload")
34
  async def upload(file: UploadFile = File(...)):
35
  extension = os.path.splitext(file.filename)[1].lower()
 
59
  "texte": texte
60
  }
61
 
62
+
63
  @app.get("/")
64
  def ping():
65
  return {"message": "L'API fonctionne ✅"}