Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,9 +14,18 @@ connection_string = os.getenv("AZURE_CON_STRING")
|
|
| 14 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
|
| 16 |
|
| 17 |
-
def ocr_pdf(
|
| 18 |
-
preprocessing_function(
|
| 19 |
-
my_blob =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
blob = BlobClient.from_connection_string(conn_str=connection_string, container_name= my_container, blob_name=my_blob)
|
| 21 |
with open("answer_paper.pdf", "rb") as data:
|
| 22 |
blob.upload_blob(data,overwrite=True)
|
|
@@ -50,23 +59,31 @@ def classify_class(incident_description):
|
|
| 50 |
return classification
|
| 51 |
|
| 52 |
|
| 53 |
-
def avatiation(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
inputs1 = gr.inputs.Textbox(label="Link for aviation log reports")
|
| 62 |
-
|
| 63 |
|
| 64 |
|
| 65 |
outputs = [gr.outputs.Textbox(label="Main Issue of the log report"),
|
| 66 |
-
gr.outputs.Textbox(label="category of the log report")
|
|
|
|
|
|
|
|
|
|
| 67 |
]
|
| 68 |
|
| 69 |
|
| 70 |
-
demo = gr.Interface(fn=avatiation,inputs=inputs1,outputs=outputs, title="ATA Auto classification using OCR and GPT3 ")
|
| 71 |
demo.launch()
|
| 72 |
|
|
|
|
| 14 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
|
| 16 |
|
| 17 |
+
def ocr_pdf(pdf_url1):
|
| 18 |
+
preprocessing_function(pdf_url1)
|
| 19 |
+
my_blob = pdf_url1.split('/')[-1]
|
| 20 |
+
blob = BlobClient.from_connection_string(conn_str=connection_string, container_name= my_container, blob_name=my_blob)
|
| 21 |
+
with open("answer_paper.pdf", "rb") as data:
|
| 22 |
+
blob.upload_blob(data,overwrite=True)
|
| 23 |
+
text = azure_ocr(blob.url,computervision_client)
|
| 24 |
+
return text.strip()
|
| 25 |
+
|
| 26 |
+
def ocr_pdf(pdf_url2):
|
| 27 |
+
preprocessing_function(pdf_url2)
|
| 28 |
+
my_blob = pdf_url2.split('/')[-1]
|
| 29 |
blob = BlobClient.from_connection_string(conn_str=connection_string, container_name= my_container, blob_name=my_blob)
|
| 30 |
with open("answer_paper.pdf", "rb") as data:
|
| 31 |
blob.upload_blob(data,overwrite=True)
|
|
|
|
| 59 |
return classification
|
| 60 |
|
| 61 |
|
| 62 |
+
def avatiation(pdf_url1,pdf_url2):
|
| 63 |
+
pdftext1 = ocr_pdf(pdf_url1)
|
| 64 |
+
pdftext2 = ocr_pdf(pdf_url2)
|
| 65 |
+
|
| 66 |
+
defect_class1 = classify_class(pdftext1)
|
| 67 |
+
main_issue1 = classify_cause(pdftext1)
|
| 68 |
+
|
| 69 |
+
defect_class2 = classify_class(pdftext2)
|
| 70 |
+
main_issue2 = classify_cause(pdftext2)
|
| 71 |
+
return main_issue1, defect_class1,main_issue2, defect_class2,
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
inputs1 = gr.inputs.Textbox(label="Link for aviation log reports")
|
| 76 |
+
inputs2 = gr.inputs.Textbox(label="Link for aviation log reports 2")
|
| 77 |
|
| 78 |
|
| 79 |
outputs = [gr.outputs.Textbox(label="Main Issue of the log report"),
|
| 80 |
+
gr.outputs.Textbox(label="category of the log report"),
|
| 81 |
+
|
| 82 |
+
gr.outputs.Textbox(label="Main Issue of the log report2"),
|
| 83 |
+
gr.outputs.Textbox(label="category of the log report2")
|
| 84 |
]
|
| 85 |
|
| 86 |
|
| 87 |
+
demo = gr.Interface(fn=avatiation,inputs= [inputs1,inputs2],outputs=outputs, title="ATA Auto classification using OCR and GPT3 ")
|
| 88 |
demo.launch()
|
| 89 |
|