Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	
		Nathan Butters
		
	commited on
		
		
					Commit 
							
							·
						
						2960307
	
1
								Parent(s):
							
							e91d43c
								
Fixed Image to Model!!!
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -7,9 +7,7 @@ import streamlit as st 
     | 
|
| 7 | 
         
             
            import logging
         
     | 
| 8 | 
         
             
            from helpers.constant import *
         
     | 
| 9 | 
         
             
            from helpers.chat import basicChat, guidedMM, mmChat
         
     | 
| 10 | 
         
            -
            import  
     | 
| 11 | 
         
            -
            import tempfile
         
     | 
| 12 | 
         
            -
            import requests
         
     | 
| 13 | 
         | 
| 14 | 
         
             
            logger = logging.getLogger(__name__)
         
     | 
| 15 | 
         
             
            logging.basicConfig(filename='app.log', level=logging.INFO)
         
     | 
| 
         @@ -28,13 +26,16 @@ if "systemPrompt" not in st.session_state: 
     | 
|
| 28 | 
         
             
            st.set_page_config(page_title="IMSA Math Helper v0.1")
         
     | 
| 29 | 
         
             
            st.title("IMSA Math Helper v0.1")
         
     | 
| 30 | 
         
             
            with st.sidebar:
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 31 | 
         
             
                # User selects a model
         
     | 
| 32 | 
         
             
                model_choice = st.radio("Please select the model:", options=["Llama","QWEN"])
         
     | 
| 33 | 
         
             
                update_model(model_choice)
         
     | 
| 34 | 
         
             
                logger.info(f"Model changed to {model_choice}.")
         
     | 
| 35 | 
         
             
                systemPrompt = st.radio("Designate a control persona:",options=["Model","Tutor"])
         
     | 
| 36 | 
         
             
                st.session_state.systemPrompt = systemPrompt
         
     | 
| 37 | 
         
            -
                liveExperience = st.checkbox("Check  
     | 
| 38 | 
         | 
| 39 | 
         
             
            st.subheader(f"This experience is currently running on {st.session_state.model}.")
         
     | 
| 40 | 
         | 
| 
         @@ -48,21 +49,17 @@ for message in st.session_state.messages: 
     | 
|
| 48 | 
         
             
                    st.markdown(message["content"])
         
     | 
| 49 | 
         | 
| 50 | 
         
             
            if liveExperience:
         
     | 
| 51 | 
         
            -
                st. 
     | 
| 52 | 
         
            -
                 
     | 
| 53 | 
         
            -
                picture = st.camera_input("Take a picture of your math work", disabled=not enable)
         
     | 
| 54 | 
         | 
| 55 | 
         
             
                if picture is not None:
         
     | 
| 56 | 
         
            -
                     
     | 
| 57 | 
         
            -
                     
     | 
| 58 | 
         
            -
                     
     | 
| 59 | 
         
            -
                     
     | 
| 60 | 
         
            -
                        f.write(picture.getbuffer())
         
     | 
| 61 | 
         
            -
                    extIP = requests.get("https://ipv4.icanhazip.com").text 
         
     | 
| 62 | 
         
            -
                    img_url = f"https://{extIP}:8501{temp_image_path}"
         
     | 
| 63 | 
         
             
                    guidedMM(st.session_state.systemPrompt, img_url)
         
     | 
| 64 | 
         
             
            else:
         
     | 
| 65 | 
         
            -
                st.info("Please select an example image to understand the basic potential of the app  
     | 
| 66 | 
         
             
                example = st.selectbox("Select an example image", options=["Example 1", "Example 2"])
         
     | 
| 67 | 
         
             
                if example == "Example 1":
         
     | 
| 68 | 
         
             
                    img_url = "https://huggingface.co/spaces/butterswords/MM_Math_Helper/resolve/main/tempDir/example1.png"
         
     | 
| 
         | 
|
| 7 | 
         
             
            import logging
         
     | 
| 8 | 
         
             
            from helpers.constant import *
         
     | 
| 9 | 
         
             
            from helpers.chat import basicChat, guidedMM, mmChat
         
     | 
| 10 | 
         
            +
            import base64
         
     | 
| 
         | 
|
| 
         | 
|
| 11 | 
         | 
| 12 | 
         
             
            logger = logging.getLogger(__name__)
         
     | 
| 13 | 
         
             
            logging.basicConfig(filename='app.log', level=logging.INFO)
         
     | 
| 
         | 
|
| 26 | 
         
             
            st.set_page_config(page_title="IMSA Math Helper v0.1")
         
     | 
| 27 | 
         
             
            st.title("IMSA Math Helper v0.1")
         
     | 
| 28 | 
         
             
            with st.sidebar:
         
     | 
| 29 | 
         
            +
                st.info("""This prototype is designed to help students explore the potential and risks of using LLMs to help learn math. 
         
     | 
| 30 | 
         
            +
                This version (v.01) exists to demonstrate an end-to-end proof of concept for the students to engage with to identify
         
     | 
| 31 | 
         
            +
                hazards within the system design. Future iterations will include the constraints they devise to improve the system.""")
         
     | 
| 32 | 
         
             
                # User selects a model
         
     | 
| 33 | 
         
             
                model_choice = st.radio("Please select the model:", options=["Llama","QWEN"])
         
     | 
| 34 | 
         
             
                update_model(model_choice)
         
     | 
| 35 | 
         
             
                logger.info(f"Model changed to {model_choice}.")
         
     | 
| 36 | 
         
             
                systemPrompt = st.radio("Designate a control persona:",options=["Model","Tutor"])
         
     | 
| 37 | 
         
             
                st.session_state.systemPrompt = systemPrompt
         
     | 
| 38 | 
         
            +
                liveExperience = st.checkbox("Check to enable the live experience.")
         
     | 
| 39 | 
         | 
| 40 | 
         
             
            st.subheader(f"This experience is currently running on {st.session_state.model}.")
         
     | 
| 41 | 
         | 
| 
         | 
|
| 49 | 
         
             
                    st.markdown(message["content"])
         
     | 
| 50 | 
         | 
| 51 | 
         
             
            if liveExperience:
         
     | 
| 52 | 
         
            +
                enable = st.checkbox("Enable camera to upload a picture of your math problem.")
         
     | 
| 53 | 
         
            +
                picture = st.camera_input("Take a picture", disabled=not enable)
         
     | 
| 
         | 
|
| 54 | 
         | 
| 55 | 
         
             
                if picture is not None:
         
     | 
| 56 | 
         
            +
                    st.image(picture)
         
     | 
| 57 | 
         
            +
                    picBytes= picture.getvalue()
         
     | 
| 58 | 
         
            +
                    b64IMG = base64.b64encode(picBytes).decode('utf-8')
         
     | 
| 59 | 
         
            +
                    img_url = f"data:image/jpeg;base64,{b64IMG}"
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 60 | 
         
             
                    guidedMM(st.session_state.systemPrompt, img_url)
         
     | 
| 61 | 
         
             
            else:
         
     | 
| 62 | 
         
            +
                st.info("Please select an example image to understand the basic potential of the app before using the live app. You can ask the model a question about these images to see how it responds.")
         
     | 
| 63 | 
         
             
                example = st.selectbox("Select an example image", options=["Example 1", "Example 2"])
         
     | 
| 64 | 
         
             
                if example == "Example 1":
         
     | 
| 65 | 
         
             
                    img_url = "https://huggingface.co/spaces/butterswords/MM_Math_Helper/resolve/main/tempDir/example1.png"
         
     |