Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,12 +24,15 @@ def run_GOT(image, tokenizer, model):
|
|
| 24 |
image_path = f"{unique_id}.png"
|
| 25 |
|
| 26 |
image.save(image_path)
|
|
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
# Use the model to extract text
|
| 30 |
res = model.chat(tokenizer, image_path, ocr_type='ocr') # Extract plain text
|
|
|
|
| 31 |
return res
|
| 32 |
except Exception as e:
|
|
|
|
| 33 |
return f"Error: {str(e)}"
|
| 34 |
finally:
|
| 35 |
# Clean up the saved image
|
|
@@ -39,12 +42,7 @@ def run_GOT(image, tokenizer, model):
|
|
| 39 |
# Function to highlight keyword in text
|
| 40 |
def highlight_keyword(text, keyword):
|
| 41 |
if keyword:
|
| 42 |
-
|
| 43 |
-
highlighted_text = text
|
| 44 |
-
highlighted_text = highlighted_text.replace(keyword, f"<mark>{keyword}</mark>")
|
| 45 |
-
highlighted_text = highlighted_text.replace(keyword.lower(), f"<mark>{keyword.lower()}</mark>")
|
| 46 |
-
highlighted_text = highlighted_text.replace(keyword.upper(), f"<mark>{keyword.upper()}</mark>")
|
| 47 |
-
highlighted_text = highlighted_text.replace(keyword.capitalize(), f"<mark>{keyword.capitalize()}</mark>")
|
| 48 |
return highlighted_text
|
| 49 |
return text
|
| 50 |
|
|
@@ -87,3 +85,4 @@ if uploaded_image:
|
|
| 87 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 88 |
else:
|
| 89 |
st.error(result_text)
|
|
|
|
|
|
| 24 |
image_path = f"{unique_id}.png"
|
| 25 |
|
| 26 |
image.save(image_path)
|
| 27 |
+
st.write(f"Saved image to {image_path}")
|
| 28 |
|
| 29 |
try:
|
| 30 |
# Use the model to extract text
|
| 31 |
res = model.chat(tokenizer, image_path, ocr_type='ocr') # Extract plain text
|
| 32 |
+
st.write(f"Raw result: {res}") # Debug output
|
| 33 |
return res
|
| 34 |
except Exception as e:
|
| 35 |
+
st.error(f"Error: {str(e)}") # Display any errors
|
| 36 |
return f"Error: {str(e)}"
|
| 37 |
finally:
|
| 38 |
# Clean up the saved image
|
|
|
|
| 42 |
# Function to highlight keyword in text
|
| 43 |
def highlight_keyword(text, keyword):
|
| 44 |
if keyword:
|
| 45 |
+
highlighted_text = text.replace(keyword, f"<mark>{keyword}</mark>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return highlighted_text
|
| 47 |
return text
|
| 48 |
|
|
|
|
| 85 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 86 |
else:
|
| 87 |
st.error(result_text)
|
| 88 |
+
|