Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import pytesseract
|
| 4 |
+
|
| 5 |
+
def process_input(image,text):
|
| 6 |
+
try:
|
| 7 |
+
if image is not None:
|
| 8 |
+
# Convert the image to RGB format
|
| 9 |
+
img_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 10 |
+
# Perform OCR on the uploaded image
|
| 11 |
+
text_from_image = pytesseract.image_to_string(img_rgb)
|
| 12 |
+
combined_text = f"{text}\n{text_from_image}"
|
| 13 |
+
else:
|
| 14 |
+
combined_text = text
|
| 15 |
+
# Call your Generate function with the combined text
|
| 16 |
+
headline = Generate(combined_text,Server)
|
| 17 |
+
return headline
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {e}"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
interface = gr.Interface(fn=process_input, inputs=["image","text"], outputs=["text"], title="News Headline Generator with OCR")
|
| 23 |
+
interface.launch()
|