CwAnkit07 commited on
Commit
7737855
·
verified ·
1 Parent(s): 42adfb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ # Load AI Model for Question Extraction
6
+ question_extractor = pipeline("text-classification", model="textattack/bert-base-uncased-MRPC")
7
+
8
+ app = FastAPI()
9
+
10
+ # Define API Input Format
11
+ class OCRText(BaseModel):
12
+ text: str
13
+
14
+ @app.post("/extract_question")
15
+ def extract_question(data: OCRText):
16
+ text = data.text
17
+ lines = text.split("\n")
18
+
19
+ # Use AI Model to Identify Question Parts
20
+ ranked_lines = sorted(lines, key=lambda line: question_extractor(line)[0]['score'], reverse=True)
21
+ top_sentences = [line for line in ranked_lines[:3] if len(line) > 10] # Keep Top 3 Sentences
22
+
23
+ question_text = " ".join(top_sentences)
24
+
25
+ return {"extracted_question": question_text}