Spaces:
Runtime error
Runtime error
File size: 1,499 Bytes
c97e107 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import gradio as gr
from transformers import pipeline
# Load the models
ocr_model = pipeline("image-to-text", model="pragnakalp/OCR-image-to-text")
math_model = pipeline("text-generation", model="Qwen/Qwen2.5-Math")
# Define functions for OCR and math reasoning
def process_image(image):
# Extract text from image using OCR
ocr_text = ocr_model(image)[0]['generated_text']
return ocr_text
def process_math(text):
# Use Qwen2.5-Math model to interpret the text
math_result = math_model(text, max_length=50)[0]['generated_text']
return math_result
# Create a Gradio interface
def combined_process(image=None, text=None):
history = []
# If an image is uploaded, process it with OCR
if image:
extracted_text = process_image(image)
history.append(("OCR Text", extracted_text))
else:
extracted_text = text
# Pass extracted or entered text to the math model
if extracted_text:
result = process_math(extracted_text)
history.append(("Math Result", result))
return history
# Gradio Interface with text and image inputs
iface = gr.Interface(
fn=combined_process,
inputs=[
gr.inputs.Image(label="Upload an Image for OCR"),
gr.inputs.Textbox(label="Or Enter Text for Math Processing")
],
outputs=gr.outputs.JSON(label="Interaction History"),
title="OCR and Math Assistant",
description="Upload an image or enter text for OCR or math processing."
)
iface.launch()
|