Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import gradio as gr
|
|
| 7 |
import cv2
|
| 8 |
import numpy as np
|
| 9 |
import scipy
|
|
|
|
| 10 |
|
| 11 |
model_path = "pretrained_models/model_qnrf.pth"
|
| 12 |
url = "https://drive.google.com/uc?id=1nnIHPaV9RGqK8JHL645zmRvkNrahD9ru"
|
|
@@ -20,6 +21,10 @@ model.load_state_dict(torch.load(model_path, device))
|
|
| 20 |
model.eval()
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def predict(inp):
|
| 24 |
inp = Image.fromarray(inp.astype('uint8'), 'RGB')
|
| 25 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
|
@@ -42,13 +47,41 @@ outputs = [
|
|
| 42 |
gr.Label(label="Predicted Count")
|
| 43 |
]
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
gr.Interface(fn=predict,
|
| 50 |
inputs=inputs,
|
| 51 |
-
outputs=outputs,
|
| 52 |
-
title=
|
| 53 |
description=desc,
|
| 54 |
-
allow_flagging="never"
|
|
|
|
|
|
| 7 |
import cv2
|
| 8 |
import numpy as np
|
| 9 |
import scipy
|
| 10 |
+
import base64
|
| 11 |
|
| 12 |
model_path = "pretrained_models/model_qnrf.pth"
|
| 13 |
url = "https://drive.google.com/uc?id=1nnIHPaV9RGqK8JHL645zmRvkNrahD9ru"
|
|
|
|
| 21 |
model.eval()
|
| 22 |
|
| 23 |
|
| 24 |
+
def image_to_base64(image_path):
|
| 25 |
+
with open(image_path, "rb") as image_file:
|
| 26 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 27 |
+
|
| 28 |
def predict(inp):
|
| 29 |
inp = Image.fromarray(inp.astype('uint8'), 'RGB')
|
| 30 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
|
|
|
| 47 |
gr.Label(label="Predicted Count")
|
| 48 |
]
|
| 49 |
|
| 50 |
+
# Convert your image to Base64
|
| 51 |
+
logo_base64 = image_to_base64("corporate.png")
|
| 52 |
+
logo_src = f"data:image/png;base64,{logo_base64}"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
desc = f"""
|
| 56 |
+
<style>
|
| 57 |
+
/* Add padding at the bottom of the interface to prevent overlap with the absolutely positioned image */
|
| 58 |
+
body, html, .interface {{
|
| 59 |
+
margin: 0;
|
| 60 |
+
padding-bottom: 120px; /* Adjust this value based on the height of your image */
|
| 61 |
+
}}
|
| 62 |
+
/* Position your image at the bottom left of the interface */
|
| 63 |
+
.logo-img {{
|
| 64 |
+
width: 150px; /* Set width to auto to keep the original image size */
|
| 65 |
+
bottom: 10px;
|
| 66 |
+
left: 10px;
|
| 67 |
+
}}
|
| 68 |
+
/* Style for your text to make sure it does not overlap the logo */
|
| 69 |
+
.with-margin {{
|
| 70 |
+
padding-left: 120px; /* This padding should be more than the width of your logo to prevent text overlap */
|
| 71 |
+
}}
|
| 72 |
+
</style>
|
| 73 |
+
<div class="description">
|
| 74 |
+
<img src="{logo_src}" alt='Logo' class="logo-img" width="300px"/>
|
| 75 |
+
<h4 class="with-margin">AI-Powered Audience Insights</h4>
|
| 76 |
+
<p class="with-margin">Seamlessly count and analyze your conference attendees with cutting-edge neural language models</p>
|
| 77 |
+
</div>
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
|
| 81 |
gr.Interface(fn=predict,
|
| 82 |
inputs=inputs,
|
| 83 |
+
outputs=outputs,
|
| 84 |
+
title=" ",
|
| 85 |
description=desc,
|
| 86 |
+
allow_flagging="never",
|
| 87 |
+
css="footer{display:none !important}").launch()
|