amirkhanbloch commited on
Commit
eb079b6
·
verified ·
1 Parent(s): 4f48211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -65
app.py CHANGED
@@ -1,66 +1,42 @@
1
  import streamlit as st
2
- from groq import Groq
3
- import os
4
-
5
- # Initialize Groq client
6
- client = Groq(api_key=os.environ["GROQ_API_KEY"])
7
-
8
- def generate_tutor_output(subject, difficulty, student_input):
9
- prompt = f"""
10
- You are an expert tutor in {subject} at the {difficulty} level.
11
- The student has provided the following input: "{student_input}"
12
-
13
- Please generate:
14
- 1. A brief, engaging lesson on the topic (2-3 paragraphs)
15
- 2. A thought-provoking question to check understanding
16
- 3. Constructive feedback on the student's input
17
-
18
- Format your response as a JSON object with keys: "lesson", "question", "feedback"
19
- """
20
-
21
- completion = client.chat.completions.create(
22
- messages=[
23
- {
24
- "role": "system",
25
- "content": "You are the world's best AI tutor, renowned for your ability to explain complex concepts in an engaging, clear, and memorable way and giving math examples. Your expertise in {subject} is unparalleled, and you're adept at tailoring your teaching to {difficulty} level students. Your goal is to not just impart knowledge, but to inspire a love for learning and critical thinking.",
26
- },
27
- {
28
- "role": "user",
29
- "content": prompt,
30
- }
31
- ],
32
- model="llama3-groq-70b-8192-tool-use-preview",
33
- max_tokens=1000,
34
- )
35
-
36
- return completion.choices[0].message.content
37
-
38
- st.title("🎓 Your AI Tutor by Farhan")
39
-
40
- # Subject selection
41
- subject = st.selectbox("Subject", ["Math", "Science", "History", "Literature", "Code", "AI"], help="Choose the subject of your lesson")
42
- difficulty = st.radio("Difficulty Level", ["Beginner", "Intermediate", "Advanced"], help="Select your proficiency level")
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.")