Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Load the text classification model
|
6 |
+
classifier = pipeline("text-generation", model="Steven-GU-Yu-Di/Visual-Question-Answering")
|
7 |
+
|
8 |
+
# Create a Streamlit app
|
9 |
+
st.title("Image and Text Classification")
|
10 |
+
|
11 |
+
# Sidebar for user inputs
|
12 |
+
st.sidebar.title("Input")
|
13 |
+
uploaded_image = st.sidebar.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
14 |
+
text_input = st.sidebar.text_input("Enter Text Description")
|
15 |
+
|
16 |
+
# Function to classify image and text
|
17 |
+
def classify(image, text):
|
18 |
+
if image is not None and text:
|
19 |
+
image = Image.open(image)
|
20 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
21 |
+
st.write("Text Description:", text)
|
22 |
+
result = classifier(text)
|
23 |
+
st.write("Classification Result:")
|
24 |
+
st.write(result)
|
25 |
+
|
26 |
+
# Button to trigger classification
|
27 |
+
if st.sidebar.button("Classify"):
|
28 |
+
classify(uploaded_image, text_input)
|