Spaces:
Runtime error
Runtime error
rahul-appu
commited on
Commit
•
d8cad3b
1
Parent(s):
50341c8
Add application file
Browse files- .dockerignore +1 -0
- Dockerfile +17 -0
- main.py +35 -0
- requirements.txt +4 -0
.dockerignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__
|
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Base Image
|
2 |
+
FROM python:3.12
|
3 |
+
|
4 |
+
# Ensure the Python output is not buffered
|
5 |
+
ENV PYTHONUNBUFFERED True
|
6 |
+
|
7 |
+
# Set the working directory in the container
|
8 |
+
WORKDIR /app
|
9 |
+
|
10 |
+
# Copy all the application files to the working directory
|
11 |
+
COPY . /app
|
12 |
+
|
13 |
+
# Install the required Python packages
|
14 |
+
RUN pip install -r requirements.txt
|
15 |
+
|
16 |
+
# Command to run the web service
|
17 |
+
CMD ["python", "main.py"]
|
main.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
model_dir = 'edithram23/Redaction'
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_dir)
|
7 |
+
|
8 |
+
def mask_generation(text):
|
9 |
+
import re
|
10 |
+
inputs = ["Mask Generation: " + text]
|
11 |
+
inputs = tokenizer(inputs, max_length=500, truncation=True, return_tensors="pt")
|
12 |
+
output = model.generate(**inputs, num_beams=8, do_sample=True, max_length=len(text)+10)
|
13 |
+
decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
|
14 |
+
predicted_title = decoded_output.strip()
|
15 |
+
pattern = r'\[.*?\]'
|
16 |
+
# Replace all occurrences of the pattern with [redacted]
|
17 |
+
redacted_text = re.sub(pattern, '[redacted]', predicted_title)
|
18 |
+
return redacted_text
|
19 |
+
|
20 |
+
from fastapi import FastAPI
|
21 |
+
import uvicorn
|
22 |
+
|
23 |
+
app = FastAPI()
|
24 |
+
|
25 |
+
@app.get("/")
|
26 |
+
async def hello():
|
27 |
+
return {"msg" : "Live"}
|
28 |
+
|
29 |
+
@app.post("/mask")
|
30 |
+
async def mask_input(query):
|
31 |
+
output = mask_generation(query)
|
32 |
+
return {"data" : output}
|
33 |
+
|
34 |
+
if __name__ == '__main__':
|
35 |
+
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True, workers=1)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.111.0
|
2 |
+
transformers==4.41.2
|
3 |
+
uvicorn==0.30.1
|
4 |
+
torch
|