Spaces:
Runtime error
Runtime error
Commit
·
0c9b828
1
Parent(s):
98d9b42
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from io import BytesIO
|
4 |
+
from PIL import Image
|
5 |
+
import os
|
6 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
7 |
+
|
8 |
+
|
9 |
+
api_key = os.environ['API_KEY']
|
10 |
+
|
11 |
+
API_URL = "https://api-inference.huggingface.co/models/Hrishikesh332/autotrain-meme-classification-42897109437"
|
12 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
13 |
+
|
14 |
+
def query(filename):
|
15 |
+
with open(filename, "rb") as f:
|
16 |
+
data = f.read()
|
17 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
18 |
+
return response.json()
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
st.markdown("<h1 style='text-align: center;'>Memeter 💬</h1>", unsafe_allow_html=True)
|
23 |
+
st.markdown("---")
|
24 |
+
with st.sidebar:
|
25 |
+
st.title("Memometer")
|
26 |
+
st.caption('''
|
27 |
+
Memeter is an application used for the classification of whether the images provided is meme or not meme
|
28 |
+
''', unsafe_allow_html=False)
|
29 |
+
|
30 |
+
img = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
|
31 |
+
|
32 |
+
# def predict(image):
|
33 |
+
# inputs = extractor(images=image, return_tensors="pt")
|
34 |
+
|
35 |
+
# outputs = model(**inputs)
|
36 |
+
# scores = outputs.logits.detach().numpy()
|
37 |
+
# return scores
|
38 |
+
|
39 |
+
if img is not None:
|
40 |
+
try:
|
41 |
+
image = Image.open(BytesIO(img.read()))
|
42 |
+
output = query(image)
|
43 |
+
st.write("Predicted Output:", Output)
|
44 |
+
except:
|
45 |
+
st.write("Pleas do upload the image in the correct format!")
|
46 |
+
|
47 |
+
|