forked from SimranAnand1/LLMtutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (51 loc) · 1.79 KB
/
Copy pathmain.py
File metadata and controls
63 lines (51 loc) · 1.79 KB
1
2
3
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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()