Spaces:
Sleeping
Sleeping
QMonitor Admin commited on
Commit ·
723c64a
1
Parent(s): e5664b9
Fix API configuration and endpoint format
Browse files
app.py
CHANGED
|
@@ -169,17 +169,18 @@ def parse_form_text(text):
|
|
| 169 |
return data
|
| 170 |
|
| 171 |
# API endpoint untuk prediksi
|
| 172 |
-
def predict_api(
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
# Lakukan OCR
|
| 180 |
result = perform_ocr(img)
|
| 181 |
|
| 182 |
-
return
|
| 183 |
|
| 184 |
# Interface web dengan Gradio
|
| 185 |
with gr.Blocks() as demo:
|
|
@@ -222,6 +223,10 @@ with gr.Blocks() as demo:
|
|
| 222 |
outputs=[nama_output, posisi_output, lokasi_output, tanggal_output,
|
| 223 |
jenis_output, uraian_output, tindakan_output]
|
| 224 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
# Konfigurasi API
|
| 227 |
demo.queue()
|
|
|
|
| 169 |
return data
|
| 170 |
|
| 171 |
# API endpoint untuk prediksi
|
| 172 |
+
def predict_api(img):
|
| 173 |
+
# Konversi file gambar ke numpy array jika tidak dalam format array numpy
|
| 174 |
+
if not isinstance(img, np.ndarray):
|
| 175 |
+
if hasattr(img, 'read'): # jika img adalah file object
|
| 176 |
+
img = np.array(Image.open(io.BytesIO(img.read())))
|
| 177 |
+
else: # jika img adalah Image dari gradio
|
| 178 |
+
img = np.array(img)
|
| 179 |
|
| 180 |
# Lakukan OCR
|
| 181 |
result = perform_ocr(img)
|
| 182 |
|
| 183 |
+
return result
|
| 184 |
|
| 185 |
# Interface web dengan Gradio
|
| 186 |
with gr.Blocks() as demo:
|
|
|
|
| 223 |
outputs=[nama_output, posisi_output, lokasi_output, tanggal_output,
|
| 224 |
jenis_output, uraian_output, tindakan_output]
|
| 225 |
)
|
| 226 |
+
|
| 227 |
+
# Menambahkan endpoint API
|
| 228 |
+
demo.queue()
|
| 229 |
+
gr.Interface(fn=predict_api, inputs=gr.Image(type="pil"), outputs="json").launch(share=True)
|
| 230 |
|
| 231 |
# Konfigurasi API
|
| 232 |
demo.queue()
|