Spaces:
No application file
No application file
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
class StudyText(BaseModel):
|
| 8 |
+
text: str
|
| 9 |
+
|
| 10 |
+
def extract_study_timeline(text: str):
|
| 11 |
+
screening = re.search(r'(?:Screening|Pre-study observation|Initial Check)(?:\s*(?:phase|period))?\s*(?:is|:|-|of|lasts)?\s*(\d+)\s*weeks?', text, re.IGNORECASE)
|
| 12 |
+
treatment = re.search(r'(?:Treatment|Intervention|Therapy|Dosing phase|Main study(?:\s*period)?)(?:\s*(?:is|:|-|of|lasts))?\s*(\d+)\s*weeks?', text, re.IGNORECASE)
|
| 13 |
+
follow_up = re.search(r'(?:Follow[-\s]*up|Recovery|Post-study monitoring|Observation phase|After-treatment)(?:\s*(?:is|:|-|of|lasts))?\s*(\d+)\s*weeks?', text, re.IGNORECASE)
|
| 14 |
+
|
| 15 |
+
return {
|
| 16 |
+
"Screening": int(screening.group(1)) if screening else None,
|
| 17 |
+
"Treatment": int(treatment.group(1)) if treatment else None,
|
| 18 |
+
"Follow-Up": int(follow_up.group(1)) if follow_up else None
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
@app.post("/extract-timeline/")
|
| 22 |
+
async def extract_timeline(request: StudyText):
|
| 23 |
+
return extract_study_timeline(request.text)
|
| 24 |
+
|
| 25 |
+
@app.get("/")
|
| 26 |
+
async def root():
|
| 27 |
+
return {"message": "Study Timeline Extractor API is running. Use /extract-timeline/ to extract data."}
|