Grinding commited on
Commit
2653ef9
·
verified ·
1 Parent(s): d9e5730

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -0
  2. app.py +39 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # The Dockerfile is nearly identical to the previous services [cite: 289]
2
+ FROM python:3.9-slim
3
+ WORKDIR /code
4
+ COPY ./requirements.txt /code/requirements.txt
5
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
6
+ COPY ./app.py /code/app.py
7
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adapted from source [cite: 262-285]
2
+ from fastapi import FastAPI, HTTPException
3
+ from pydantic import BaseModel
4
+ from transformers import pipeline
5
+ from typing import List
6
+
7
+ app = FastAPI()
8
+
9
+ class SentenceListPayload(BaseModel):
10
+ sentences: List[str]
11
+
12
+ # Load the text classification pipeline on startup
13
+ try:
14
+ action_item_classifier = pipeline(
15
+ "text-classification",
16
+ model="knkarthick/Action_Items",
17
+ device="cpu",
18
+ )
19
+ except Exception as e:
20
+ action_item_classifier = None
21
+ print(f"Error loading action item model: {e}")
22
+
23
+ @app.post("/classify-action-items")
24
+ async def classify_sentences(payload: SentenceListPayload):
25
+ if not action_item_classifier:
26
+ raise HTTPException(status_code=503, detail="Action item model is not available.")
27
+
28
+ results = action_item_classifier(payload.sentences)
29
+
30
+ # Filter for sentences classified as action items with a confidence threshold
31
+ action_items = []
32
+ for i, sentence in enumerate(payload.sentences):
33
+ if results[i]['label'] == 'LABEL_1' and results[i]['score'] > 0.8:
34
+ action_items.append({
35
+ "sentence": sentence,
36
+ "confidence": results[i]['score']
37
+ })
38
+
39
+ return {"action_items": action_items}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ torch
4
+ transformers
5
+ pydantic
6
+ typing