Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
import os
|
2 |
import io
|
3 |
from pdf2image import convert_from_path
|
4 |
-
from
|
5 |
import base64
|
6 |
import asyncio
|
7 |
from datetime import datetime
|
8 |
import gradio as gr
|
9 |
|
10 |
# We'll use an environment variable for the API key in Spaces
|
11 |
-
|
12 |
|
13 |
class PDFTextExtractor:
|
14 |
def __init__(self, api_key):
|
@@ -32,7 +32,7 @@ class PDFTextExtractor:
|
|
32 |
img_base64 = base64.b64encode(img_buffer.getvalue()).decode('utf-8')
|
33 |
|
34 |
response = self.client.messages.create(
|
35 |
-
model="
|
36 |
system="""You are a doctor at a hospital. You can understand sloppy handwriting and convert it to readable text. Extract all the data from the form according to the markdown structure given below.
|
37 |
Follow this exact markdown structure:
|
38 |
# PATIENT ADMISSION FORM
|
@@ -154,7 +154,7 @@ class PDFTextExtractor:
|
|
154 |
return None
|
155 |
|
156 |
def extract_text(pdf_file):
|
157 |
-
if
|
158 |
return "Error: Anthropic API key not found. Please set the ANTHROPIC_API_KEY environment variable."
|
159 |
|
160 |
extractor = PDFTextExtractor(ANTHROPIC_API_KEY)
|
|
|
1 |
import os
|
2 |
import io
|
3 |
from pdf2image import convert_from_path
|
4 |
+
from openai import OpenAI
|
5 |
import base64
|
6 |
import asyncio
|
7 |
from datetime import datetime
|
8 |
import gradio as gr
|
9 |
|
10 |
# We'll use an environment variable for the API key in Spaces
|
11 |
+
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
12 |
|
13 |
class PDFTextExtractor:
|
14 |
def __init__(self, api_key):
|
|
|
32 |
img_base64 = base64.b64encode(img_buffer.getvalue()).decode('utf-8')
|
33 |
|
34 |
response = self.client.messages.create(
|
35 |
+
model="gpt-4o",
|
36 |
system="""You are a doctor at a hospital. You can understand sloppy handwriting and convert it to readable text. Extract all the data from the form according to the markdown structure given below.
|
37 |
Follow this exact markdown structure:
|
38 |
# PATIENT ADMISSION FORM
|
|
|
154 |
return None
|
155 |
|
156 |
def extract_text(pdf_file):
|
157 |
+
if OPENAI_API_KEY is None:
|
158 |
return "Error: Anthropic API key not found. Please set the ANTHROPIC_API_KEY environment variable."
|
159 |
|
160 |
extractor = PDFTextExtractor(ANTHROPIC_API_KEY)
|