benkada commited on
Commit
cf9785c
Β·
verified Β·
1 Parent(s): 2dd1f0a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -9
main.py CHANGED
@@ -20,7 +20,7 @@ PORT = int(os.getenv("PORT", 7860))
20
  app = FastAPI(
21
  title = "AI-Powered Web-App API",
22
  description = "Backend for summarisation, captioning & QA",
23
- version = "1.2.3", # <-- bumped
24
  )
25
 
26
  app.add_middleware(
@@ -47,15 +47,12 @@ summary_client = InferenceClient(
47
  timeout = 120,
48
  )
49
 
50
- # ➜ Upgraded QA model (higher accuracy than roberta-base)
51
  qa_client = InferenceClient(
52
- "deepset/roberta-large-squad2",
53
  token = HUGGINGFACE_TOKEN,
54
- timeout = 120,
55
  )
56
- # If you need multilingual support, swap for:
57
- # qa_client = InferenceClient("deepset/xlm-roberta-large-squad2",
58
- # token=HUGGINGFACE_TOKEN, timeout=120)
59
 
60
  image_caption_client = InferenceClient(
61
  "nlpconnect/vit-gpt2-image-captioning",
@@ -114,7 +111,6 @@ async def summarize_document(file: UploadFile = File(...)):
114
  # -------------------- Image Caption ------------------------------------------
115
  @app.post("/api/caption")
116
  async def caption_image(image: UploadFile = File(...)):
117
- """`image` field name matches frontend (was `file` before)."""
118
  try:
119
  img_bytes = await image.read()
120
  img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
@@ -149,7 +145,7 @@ async def question_answering(file: UploadFile = File(...),
149
  context = (res.get("generated_text") if isinstance(res, dict)
150
  else str(res))
151
  else:
152
- context = process_uploaded_file(file)[:3000]
153
 
154
  if not context:
155
  return {"result": "No context – cannot answer."}
 
20
  app = FastAPI(
21
  title = "AI-Powered Web-App API",
22
  description = "Backend for summarisation, captioning & QA",
23
+ version = "1.2.4", # <-- bumped
24
  )
25
 
26
  app.add_middleware(
 
47
  timeout = 120,
48
  )
49
 
50
+ # ➜ Upgraded QA model to a BigBird-RoBERTa checkpoint (better for documents)
51
  qa_client = InferenceClient(
52
+ "google/bigbird-roberta-base-squad2",
53
  token = HUGGINGFACE_TOKEN,
54
+ timeout = 180,
55
  )
 
 
 
56
 
57
  image_caption_client = InferenceClient(
58
  "nlpconnect/vit-gpt2-image-captioning",
 
111
  # -------------------- Image Caption ------------------------------------------
112
  @app.post("/api/caption")
113
  async def caption_image(image: UploadFile = File(...)):
 
114
  try:
115
  img_bytes = await image.read()
116
  img = Image.open(io.BytesIO(img_bytes)).convert("RGB")
 
145
  context = (res.get("generated_text") if isinstance(res, dict)
146
  else str(res))
147
  else:
148
+ context = process_uploaded_file(file)[:4096] # BigBird handles longer
149
 
150
  if not context:
151
  return {"result": "No context – cannot answer."}