Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
+
import pyperclip
|
| 5 |
+
|
| 6 |
+
def load_image(uploaded_file):
|
| 7 |
+
image_bytes = uploaded_file.read()
|
| 8 |
+
image = Image.open(io.BytesIO(image_bytes))
|
| 9 |
+
return image
|
| 10 |
+
|
| 11 |
+
def save_caption(caption):
|
| 12 |
+
# Function can be added here to save the caption to some database
|
| 13 |
+
print(f"Saved caption: {caption}")
|
| 14 |
+
|
| 15 |
+
def copy_to_clipboard(text):
|
| 16 |
+
pyperclip.copy(text)
|
| 17 |
+
st.success("Caption copied to clipboard!")
|
| 18 |
+
|
| 19 |
+
def get_image_file_buffer(image):
|
| 20 |
+
buf = io.BytesIO()
|
| 21 |
+
image.save(buf, format='PNG')
|
| 22 |
+
return buf.getvalue()
|