Spaces:
Sleeping
Sleeping
Commit
·
b09fe29
1
Parent(s):
9c191f5
Initial commit from Gitpod
Browse files
app.py
CHANGED
@@ -1,29 +1,27 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException
|
2 |
-
from pydantic import BaseModel
|
3 |
-
from transformers import pipeline
|
4 |
-
from fastapi.responses import StreamingResponse
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
-
import requests
|
7 |
-
import datetime
|
8 |
-
from io import BytesIO
|
9 |
-
import logging
|
10 |
import os
|
11 |
|
12 |
-
#
|
13 |
-
os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
|
14 |
-
os.environ["HF_HOME"] = "/tmp/hf_cache"
|
15 |
-
import os
|
16 |
-
|
17 |
-
# Set temp cache dirs
|
18 |
os.environ["MPLCONFIGDIR"] = "/tmp/mplconfig"
|
19 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
|
20 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
21 |
|
22 |
-
#
|
23 |
os.makedirs("/tmp/mplconfig", exist_ok=True)
|
24 |
os.makedirs("/tmp/transformers", exist_ok=True)
|
25 |
os.makedirs("/tmp/huggingface", exist_ok=True)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Configure logging
|
28 |
logging.basicConfig(level=logging.INFO)
|
29 |
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
+
# Redirect default cache paths to writable tmp
|
|
|
|
|
|
|
|
|
|
|
4 |
os.environ["MPLCONFIGDIR"] = "/tmp/mplconfig"
|
5 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers"
|
6 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
7 |
|
8 |
+
# Create the directories if they don't exist
|
9 |
os.makedirs("/tmp/mplconfig", exist_ok=True)
|
10 |
os.makedirs("/tmp/transformers", exist_ok=True)
|
11 |
os.makedirs("/tmp/huggingface", exist_ok=True)
|
12 |
|
13 |
+
|
14 |
+
|
15 |
+
from fastapi import FastAPI, HTTPException
|
16 |
+
from pydantic import BaseModel
|
17 |
+
from transformers import pipeline
|
18 |
+
from fastapi.responses import StreamingResponse
|
19 |
+
import matplotlib.pyplot as plt
|
20 |
+
import requests
|
21 |
+
import datetime
|
22 |
+
from io import BytesIO
|
23 |
+
import logging
|
24 |
+
|
25 |
# Configure logging
|
26 |
logging.basicConfig(level=logging.INFO)
|
27 |
logger = logging.getLogger(__name__)
|