Spaces:
Runtime error
Runtime error
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", | |
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) | |