Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
import requests
|
| 4 |
|
| 5 |
# Load OCR model for extracting text from images
|
|
@@ -41,24 +42,29 @@ def main():
|
|
| 41 |
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 42 |
|
| 43 |
if uploaded_file is not None:
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
import requests
|
| 5 |
|
| 6 |
# Load OCR model for extracting text from images
|
|
|
|
| 42 |
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 43 |
|
| 44 |
if uploaded_file is not None:
|
| 45 |
+
# Convert uploaded file to a PIL image
|
| 46 |
+
try:
|
| 47 |
+
image = Image.open(uploaded_file)
|
| 48 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 49 |
+
st.write("Processing...")
|
| 50 |
|
| 51 |
+
# Extract text from image
|
| 52 |
+
ocr_model = load_ocr_model()
|
| 53 |
+
extracted_text = ocr_model(image)[0]["generated_text"]
|
| 54 |
|
| 55 |
+
if extracted_text:
|
| 56 |
+
st.write("### Extracted Text:")
|
| 57 |
+
st.write(extracted_text)
|
| 58 |
|
| 59 |
+
# Send text to ChatGPT
|
| 60 |
+
st.write("### ChatGPT Explanation:")
|
| 61 |
+
explanation = chat_with_gpt(extracted_text)
|
| 62 |
+
if explanation:
|
| 63 |
+
st.write(explanation)
|
| 64 |
+
else:
|
| 65 |
+
st.error("Could not extract text. Please try again with another image.")
|
| 66 |
+
except Exception as e:
|
| 67 |
+
st.error(f"Error processing the image: {e}")
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
main()
|