init!
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
import io
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
+
# Hugging Face Transformers specific imports
|
| 8 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 9 |
+
|
| 10 |
+
# Load pre-trained model and tokenizer
|
| 11 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 14 |
+
|
| 15 |
+
def rotate_image(image, angle):
|
| 16 |
+
"""
|
| 17 |
+
Rotate the given PIL image by the given angle
|
| 18 |
+
"""
|
| 19 |
+
return image.rotate(angle, expand=True)
|
| 20 |
+
|
| 21 |
+
def main():
|
| 22 |
+
st.title("Hugging Face Streamlit Example: Rotating Image")
|
| 23 |
+
|
| 24 |
+
# Upload an image
|
| 25 |
+
st.sidebar.title("Upload Image")
|
| 26 |
+
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 27 |
+
|
| 28 |
+
# Rotation speed adjustment
|
| 29 |
+
rotation_speed = st.sidebar.slider("Rotation Speed", min_value=0, max_value=360, value=10, step=1)
|
| 30 |
+
|
| 31 |
+
if uploaded_file is not None:
|
| 32 |
+
# Display the image
|
| 33 |
+
image = Image.open(uploaded_file)
|
| 34 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 35 |
+
|
| 36 |
+
# Rotate the image at a constant speed
|
| 37 |
+
st.write("Rotating image...")
|
| 38 |
+
rotation_angle = 0
|
| 39 |
+
while True:
|
| 40 |
+
rotated_image = rotate_image(image, rotation_angle)
|
| 41 |
+
st.image(rotated_image, caption="Rotated Image", use_column_width=True)
|
| 42 |
+
time.sleep(0.1) # Adjust rotation speed
|
| 43 |
+
rotation_angle += rotation_speed
|
| 44 |
+
rotation_angle %= 360 # Keep angle within 0-359 range
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|