Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,13 @@ import easyocr
|
|
| 6 |
ocr_reader = easyocr.Reader(['en'])
|
| 7 |
|
| 8 |
def extract_text_from_image(image_path):
|
|
|
|
| 9 |
result = ocr_reader.readtext(image_path, detail=0)
|
| 10 |
-
# Join
|
| 11 |
-
ocr_text = " ".join(result)
|
| 12 |
return ocr_text
|
| 13 |
|
| 14 |
def preprocess(text):
|
|
|
|
| 15 |
return text.lower().translate(str.maketrans('', '', string.punctuation)).strip()
|
| 16 |
|
| 17 |
def detect_sarcasm(combined_text):
|
|
@@ -27,10 +28,16 @@ def detect_sarcasm(combined_text):
|
|
| 27 |
|
| 28 |
return {"sarcasm": bool(sarcasm_pred), "confidence": confidence}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
ocr_reader = easyocr.Reader(['en'])
|
| 7 |
|
| 8 |
def extract_text_from_image(image_path):
|
| 9 |
+
# Extract text lines from image
|
| 10 |
result = ocr_reader.readtext(image_path, detail=0)
|
| 11 |
+
ocr_text = " ".join(result) # Join into one string
|
|
|
|
| 12 |
return ocr_text
|
| 13 |
|
| 14 |
def preprocess(text):
|
| 15 |
+
# Lowercase, strip punctuation, and whitespace
|
| 16 |
return text.lower().translate(str.maketrans('', '', string.punctuation)).strip()
|
| 17 |
|
| 18 |
def detect_sarcasm(combined_text):
|
|
|
|
| 28 |
|
| 29 |
return {"sarcasm": bool(sarcasm_pred), "confidence": confidence}
|
| 30 |
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
# Example usage:
|
| 33 |
+
image_path = "path_to_image.jpg" # Replace with your image file path
|
| 34 |
+
typed_text = "Your favorite sarcastic phrase here"
|
| 35 |
|
| 36 |
+
ocr_text = extract_text_from_image(image_path)
|
| 37 |
+
combined_text = ocr_text + " " + typed_text
|
| 38 |
+
|
| 39 |
+
result = detect_sarcasm(combined_text)
|
| 40 |
+
print("OCR Extracted Text:", ocr_text)
|
| 41 |
+
print("Typed Text:", typed_text)
|
| 42 |
+
print("Combined Text:", combined_text)
|
| 43 |
+
print("Sarcasm Detection Result:", result)
|