-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import streamlit as st | ||
from langchain_openai import ChatOpenAI | ||
import base64 | ||
from PIL import Image | ||
from langchain.schema.messages import HumanMessage,AIMessage | ||
llm=ChatOpenAI(model="gpt-4o",max_tokens=2048) | ||
|
||
def encode_image(upload_file): | ||
image_bytes=upload_file.getvalue() | ||
base64_image=base64.b64encode(image_bytes).decode("utf-8") | ||
return base64_image | ||
|
||
|
||
def get_response(b64image): | ||
msg=llm.invoke( | ||
[ | ||
AIMessage( | ||
content=""" | ||
you are intelligent assistant who can solve any mathematical problems on derivatives, | ||
you will be shared with a image where each line contains a problem , | ||
your task will be to solve all of them with possible explanation and step by step solutions | ||
and formulas , then create a complete answer book | ||
""" | ||
), | ||
HumanMessage( | ||
content=[ | ||
{"type":"image_url", | ||
"image_url":{ | ||
"url":"data:image/jpg;base64, " + b64image, | ||
"detail":"auto" | ||
} | ||
} | ||
] | ||
) | ||
] | ||
) | ||
content=msg.content | ||
content=content.replace("\\","") | ||
return content | ||
|
||
|
||
|
||
|
||
def main(): | ||
st.title="Student Assignment Solver" | ||
upload_file=st.file_uploader("upload your assignment:",type=["jpg","png"]) | ||
if upload_file is not None: | ||
image=Image.open(upload_file) | ||
st.image(image,caption="your assignment",use_column_width=True) | ||
st.text("your assignment uploaded successfully") | ||
base64_image=encode_image(upload_file) | ||
btn=st.button("submit") | ||
if btn: | ||
response=get_response(base64_image) | ||
print(response) | ||
st.markdown(response,unsafe_allow_html=True) | ||
|
||
|
||
if __name__=="__main__": | ||
main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
you are intelligent assistant who can solve any mathematical problems on derivatives, | ||
you will be shared with a image where each line contains a problem , | ||
your task will be solve all of them with possible explanation and step by step solutions | ||
and formulas , then crate a complete answer book | ||
""" |
Binary file not shown.