Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- README.md +1 -1
- app.py +38 -38
- requirements.txt +2 -2
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 👁
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.43.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
import argparse
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
import cv2
|
|
@@ -8,51 +8,51 @@ import torch
|
|
| 8 |
import gradio as gr
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
-
sys.path.insert(0, os.path.join(os.getcwd(), ".."))
|
| 12 |
-
from unimernet.common.config import Config
|
| 13 |
-
import unimernet.tasks as tasks
|
| 14 |
-
from unimernet.processors import load_processor
|
| 15 |
|
| 16 |
|
| 17 |
-
class ImageProcessor:
|
| 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 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
|
| 58 |
def recognize_image(input_img):
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
+
import argparse
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
import cv2
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
+
# sys.path.insert(0, os.path.join(os.getcwd(), ".."))
|
| 12 |
+
# from unimernet.common.config import Config
|
| 13 |
+
# import unimernet.tasks as tasks
|
| 14 |
+
# from unimernet.processors import load_processor
|
| 15 |
|
| 16 |
|
| 17 |
+
# class ImageProcessor:
|
| 18 |
+
# def __init__(self, cfg_path):
|
| 19 |
+
# self.cfg_path = cfg_path
|
| 20 |
+
# self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 21 |
+
# self.model, self.vis_processor = self.load_model_and_processor()
|
| 22 |
|
| 23 |
+
# def load_model_and_processor(self):
|
| 24 |
+
# args = argparse.Namespace(cfg_path=self.cfg_path, options=None)
|
| 25 |
+
# cfg = Config(args)
|
| 26 |
+
# task = tasks.setup_task(cfg)
|
| 27 |
+
# model = task.build_model(cfg).to(self.device)
|
| 28 |
+
# vis_processor = load_processor('formula_image_eval', cfg.config.datasets.formula_rec_eval.vis_processor.eval)
|
| 29 |
|
| 30 |
+
# return model, vis_processor
|
| 31 |
|
| 32 |
+
# def process_single_image(self, image_path):
|
| 33 |
+
# try:
|
| 34 |
+
# raw_image = Image.open(image_path)
|
| 35 |
+
# except IOError:
|
| 36 |
+
# print(f"Error: Unable to open image at {image_path}")
|
| 37 |
+
# return
|
| 38 |
+
# # Convert PIL Image to OpenCV format
|
| 39 |
+
# open_cv_image = np.array(raw_image)
|
| 40 |
+
# # Convert RGB to BGR
|
| 41 |
+
# if len(open_cv_image.shape) == 3:
|
| 42 |
+
# # Convert RGB to BGR
|
| 43 |
+
# open_cv_image = open_cv_image[:, :, ::-1].copy()
|
| 44 |
+
# # Display the image using cv2
|
| 45 |
|
| 46 |
+
# image = self.vis_processor(raw_image).unsqueeze(0).to(self.device)
|
| 47 |
+
# output = self.model.generate({"image": image})
|
| 48 |
+
# pred = output["pred_str"][0]
|
| 49 |
+
# print(f'Prediction:\n{pred}')
|
| 50 |
|
| 51 |
+
# cv2.imshow('Original Image', open_cv_image)
|
| 52 |
+
# cv2.waitKey(0)
|
| 53 |
+
# cv2.destroyAllWindows()
|
| 54 |
|
| 55 |
+
# return pred
|
| 56 |
|
| 57 |
|
| 58 |
def recognize_image(input_img):
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
unimernet==0.2.0
|
| 2 |
-
gradio==4.
|
|
|
|
| 1 |
+
# unimernet==0.2.0
|
| 2 |
+
gradio==4.43.0
|