Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
st.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
student_input = st.text_input("Your Input", placeholder="Type your query here...", help="Enter the topic you want to learn")
|
| 44 |
-
|
| 45 |
-
if st.button("Generate Lesson"):
|
| 46 |
-
output = generate_tutor_output(subject, difficulty, student_input)
|
| 47 |
-
try:
|
| 48 |
-
parsed = eval(output) # Use `json.loads` if your output is a valid JSON string
|
| 49 |
-
st.subheader("Lesson")
|
| 50 |
-
st.markdown(parsed["lesson"])
|
| 51 |
-
st.subheader("Comprehension Question")
|
| 52 |
-
st.markdown(parsed["question"])
|
| 53 |
-
st.subheader("Feedback")
|
| 54 |
-
st.markdown(parsed["feedback"])
|
| 55 |
-
except Exception as e:
|
| 56 |
-
st.error(f"Error parsing output: {e}")
|
| 57 |
-
|
| 58 |
-
st.markdown("""
|
| 59 |
-
### How to Use
|
| 60 |
-
1. Select a subject from the dropdown.
|
| 61 |
-
2. Choose your difficulty level.
|
| 62 |
-
3. Enter the topic or question you'd like to explore.
|
| 63 |
-
4. Click 'Generate Lesson' to receive a personalized lesson, question, and feedback.
|
| 64 |
-
5. Review the AI-generated content to enhance your learning.
|
| 65 |
-
6. Feel free to ask follow-up questions or explore new topics!
|
| 66 |
-
""")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from rembg import remove
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import base64
|
| 6 |
+
|
| 7 |
+
st.set_page_config(layout="wide", page_title="Image Background Remover")
|
| 8 |
+
|
| 9 |
+
st.write("## Remove the background from your image")
|
| 10 |
+
st.write(":dog: Try uploading an image to watch the background magically removed. Full-quality images can be downloaded from the sidebar. This code is open source and available [here](https://github.com/tyler-simons/BackgroundRemoval) on GitHub. Special thanks to the [rembg library](https://github.com/danielgatis/rembg) :grin:")
|
| 11 |
+
st.sidebar.write("## Upload and download :gear:")
|
| 12 |
+
|
| 13 |
+
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
|
| 14 |
+
|
| 15 |
+
# Download the fixed image
|
| 16 |
+
def convert_image(img):
|
| 17 |
+
buf = BytesIO()
|
| 18 |
+
img.save(buf, format="PNG")
|
| 19 |
+
byte_im = buf.getvalue()
|
| 20 |
+
return byte_im
|
| 21 |
+
|
| 22 |
+
def fix_image(upload):
|
| 23 |
+
image = Image.open(upload)
|
| 24 |
+
col1.write("Original Image :camera:")
|
| 25 |
+
col1.image(image)
|
| 26 |
+
|
| 27 |
+
fixed = remove(image)
|
| 28 |
+
col2.write("Fixed Image :wrench:")
|
| 29 |
+
col2.image(fixed)
|
| 30 |
+
st.sidebar.markdown("\n")
|
| 31 |
+
st.sidebar.download_button("Download fixed image", convert_image(fixed), "fixed.png", "image/png")
|
| 32 |
+
|
| 33 |
+
col1, col2 = st.columns(2)
|
| 34 |
+
my_upload = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 35 |
+
|
| 36 |
+
if my_upload is not None:
|
| 37 |
+
if my_upload.size > MAX_FILE_SIZE:
|
| 38 |
+
st.error("The uploaded file is too large. Please upload an image smaller than 5MB.")
|
| 39 |
+
else:
|
| 40 |
+
fix_image(upload=my_upload)
|
| 41 |
+
else:
|
| 42 |
+
st.warning("Please upload an image or use the default image.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|