|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
|
|
|
model_name = "text/sentiment-analysis" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForSequenceClassification.from_pretrained(model_name) |
|
|
|
|
|
import easyocr |
|
def image_classifier(img): |
|
model = YOLO('/content/drive/MyDrive/SIH_2023/YOLO/runs/detect/train/weights/best.pt') |
|
res = model.predict(img,conf=0.25) |
|
box = res[0].boxes.xywh[0] |
|
bounding_box = box.cpu().numpy() |
|
x0 = bounding_box[0] - bounding_box[2] / 2 |
|
x1 = bounding_box[0] + bounding_box[2] / 2 |
|
y0 = bounding_box[1] - bounding_box[3] / 2 |
|
y1 = bounding_box[1] + bounding_box[3] / 2 |
|
|
|
start_point = (int(x0), int(y0)) |
|
end_point = (int(x1), int(y1)) |
|
cv2.rectangle(img, start_point, end_point, color=(0,255,0), thickness=2) |
|
|
|
reader = easyocr.Reader(['en']) |
|
|
|
|
|
result = reader.readtext(img,allowlist="0123456789") |
|
|
|
|
|
text_and_coordinates = [(entry[1], entry[0]) for entry in result] |
|
return text_and_coordinates |
|
|
|
iface = gr.Interface( |
|
fn=predict_sentiment, |
|
inputs="text", |
|
outputs="text", |
|
live=True, |
|
title="Sentiment Analysis", |
|
description="Enter a sentence to predict sentiment.", |
|
) |
|
|
|
|
|
iface.launch() |