Spaces:
Runtime error
Runtime error
File size: 1,119 Bytes
5dd5f4e fa459e5 92eb2c8 fa459e5 5dd5f4e fa459e5 |
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 |
import gradio as gr
from gradio_client import Client, handle_file
import os
# Initialize the Gradio client
client = Client("sitammeur/PicQ")
# Gradio interface function
def gradio_predict(image):
# Save the image to a temporary path
temp_path = os.path.join("temp", "gradio_upload.png")
image.save(temp_path)
try:
# Use the Gradio client to predict the result
result = client.predict(
image=handle_file(temp_path),
question="extract the complete data from the image but focus on mostly on medical prescription data",
api_name="/predict"
)
# Return the result as output
return f"Prediction: {result}"
finally:
# Clean up the temporary file
if os.path.exists(temp_path):
os.remove(temp_path)
# Gradio interface setup
iface = gr.Interface(
fn=gradio_predict,
inputs=gr.Image(type="pil"),
outputs="text",
live=False
)
if __name__ == '__main__':
if not os.path.exists("temp"):
os.makedirs("temp")
# Launch Gradio interface
iface.launch(share=True)
|