Olivier-52 commited on
Commit
e61842c
·
1 Parent(s): 3f22cf8

Init commit

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +65 -0
  3. requirements.txt +13 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /home/app
4
+
5
+ RUN apt-get update -y
6
+ RUN apt-get install nano unzip -y
7
+ RUN apt install curl -y
8
+
9
+ RUN curl -fsSL https://get.deta.dev/cli.sh | sh
10
+
11
+ COPY requirements.txt /dependencies/requirements.txt
12
+ RUN pip install -r /dependencies/requirements.txt
13
+
14
+ COPY . /home/app
15
+
16
+ CMD gunicorn app:app --bind 0.0.0.0:$PORT --worker-class uvicorn.workers.UvicornWorker
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import uvicorn
3
+ import pandas as pd
4
+ from fastapi import FastAPI
5
+
6
+ description = """
7
+ # Climate news generator
8
+
9
+ Generate a random news about climate change from [readerbench/fakenews-climate-fr](https://huggingface.co/datasets/readerbench/fakenews-climate-fr) dataset.
10
+
11
+ Use for testing data pipelines.
12
+
13
+ Where you can:
14
+ * `/get_news` : Get a random news
15
+
16
+ Check out documentation for more information on each endpoint.
17
+ """
18
+
19
+ tags_metadata = [
20
+ {
21
+ "name": "Generator",
22
+ "description": "Endpoints that generate news about climate change",
23
+ },
24
+ ]
25
+
26
+ data = pd.read_csv("hf://datasets/readerbench/fakenews-climate-fr/fake-fr.csv")
27
+
28
+ app = FastAPI(
29
+ title="API for Climate news generator",
30
+ description=description,
31
+ version="1.0",
32
+ contact={
33
+ "name": "Olivier-52",
34
+ "url": "https://huggingface.co/Olivier-52",
35
+ },
36
+ openapi_tags=tags_metadata,)
37
+
38
+ @app.get("/")
39
+ def index():
40
+ """Return a message to the user.
41
+
42
+ This endpoint does not take any parameters and returns a message
43
+ to the user. It is used to test the API.
44
+
45
+ Returns:
46
+ str: A message to the user.
47
+ """
48
+ return "Hello world! Go to /docs to try the API."
49
+
50
+ @app.get("/get_news", tags=["Generator"])
51
+ def get_news():
52
+ """Return a random news about climate change.
53
+
54
+ This endpoint does not take any parameters and returns a random news
55
+ about climate change in JSON format.
56
+
57
+ Returns:
58
+ dict: A JSON object containing a random news about climate change.
59
+ """
60
+ if data.empty:
61
+ return {"error": "No data available"}
62
+ return data.sample(1).to_json(orient="records")
63
+
64
+ if __name__ == "__main__":
65
+ uvicorn.run(app, host="localhost", port=8000)
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mlflow==2.21.3
2
+ scikit-learn==1.4.2
3
+ requests>=2.31.0,<3
4
+ fastapi
5
+ uvicorn[standard]
6
+ pydantic
7
+ typing
8
+ pandas
9
+ gunicorn
10
+ openpyxl
11
+ boto3
12
+ python-multipart
13
+ dotenv