Loren commited on
Commit
457a7b3
·
verified ·
1 Parent(s): ce9bad1

Upload 2 files

Browse files
Files changed (2) hide show
  1. app/database.py +1 -0
  2. app/main.py +38 -38
app/database.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from typing import List, Dict
3
  import duckdb
 
4
  from huggingface_hub import hf_hub_download
5
 
6
  # Initialisations
 
1
  import os
2
  from typing import List, Dict
3
  import duckdb
4
+ import pandas as pd
5
  from huggingface_hub import hf_hub_download
6
 
7
  # Initialisations
app/main.py CHANGED
@@ -1,38 +1,38 @@
1
- from fastapi import FastAPI, Query
2
- from typing import List
3
- from app import database
4
- from fastapi.middleware.cors import CORSMiddleware
5
-
6
- app = FastAPI(
7
- title="Articles API",
8
- description="API pour récupérer articles et tags depuis SQLite",
9
- version="1.0"
10
- )
11
-
12
- # CORS pour permettre l'accès depuis le navigateur
13
- app.add_middleware(
14
- CORSMiddleware,
15
- allow_origins=["*"], # autorise toutes les origines
16
- allow_credentials=True,
17
- allow_methods=["*"],
18
- allow_headers=["*"],
19
- )
20
-
21
- @app.get("/get_tags")
22
- def get_tags():
23
- """
24
- Retourne la liste de tous les tags
25
- """
26
- tags = database.fetch_tags()
27
- return {"tags": tags}
28
-
29
- @app.get("/get_articles_with_tags")
30
- def get_articles_with_tags(
31
- tags: List[str] = Query(..., description="Liste des tags à filtrer")
32
- ):
33
- """
34
- Retourne les articles correspondant aux tags donnés
35
- """
36
- articles = database.fetch_articles_by_tags(tags)
37
- return {"tags": tags,
38
- "articles": articles}
 
1
+ from fastapi import FastAPI, Query
2
+ from typing import List
3
+ from app import database
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+
6
+ app = FastAPI(
7
+ title="Articles API",
8
+ description="API pour récupérer articles et tags depuis SQLite",
9
+ version="1.0"
10
+ )
11
+
12
+ # CORS pour permettre l'accès depuis le navigateur
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"], # autorise toutes les origines
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"],
19
+ )
20
+
21
+ @app.get("/get_tags")
22
+ def get_tags():
23
+ """
24
+ Retourne la liste de tous les tags
25
+ """
26
+ tags = database.fetch_tags()
27
+ return {"tags": tags}
28
+
29
+ @app.get("/get_articles_with_tags")
30
+ def get_articles_with_tags(
31
+ tags: List[str] = Query(..., description="Liste des tags à filtrer")
32
+ ):
33
+ """
34
+ Retourne les articles correspondant aux tags donnés
35
+ """
36
+ articles = database.fetch_articles_by_tags(tags)
37
+ return {"tags": tags,
38
+ "articles": articles}