Skip to content

Commit

Permalink
tutorial63
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed May 14, 2024
1 parent b712658 commit 572111d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion tutorial2/single_url.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from langchain.document_loaders import youtube
import io

loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/3Qkkxp48284")
loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/jYbcuZP40p8")
docs=loader.load()
print(docs)
with io.open("transcript.txt","w",encoding="utf-8")as f1:
Expand Down
2 changes: 1 addition & 1 deletion tutorial2/transcript.txt

Large diffs are not rendered by default.

Binary file removed tutorial60/~$tutorial60.pptx
Binary file not shown.
57 changes: 57 additions & 0 deletions tutorial63/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import streamlit as st
import base64
from langchain.schema.messages import HumanMessage,AIMessage
from langchain_openai import ChatOpenAI
from PIL import Image
chain=ChatOpenAI(model="gpt-4O",max_tokens=1024)

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,qsn):
msg=chain.invoke(
[
AIMessage(
content="you are a useful and intelligent bot who is very good at ocr related task , such getting insights from images of invoices"
),
HumanMessage(
content=[
{"type":"text","text":qsn},
{
"type": "image_url",
"image_url":f"data:image/jpg;base64,{b64image}"
}
]
)
]
)
return msg.content


# if "conversation" not in st.session_state:
# st.session_state.conversation=[]



def main():
st.title("INVOICE ANALYSIS SYSTEM")
upload_file=st.file_uploader("upload the invoice image..",type=["jpg"])
if upload_file is not None:
image=Image.open(upload_file)
st.image(image,caption="your uploaded invoice",use_column_width=True)
st.write("invoice image uploaded successfully")
b64_image=encode_image(upload_file)
st.success("image converted successfully")
user_question=st.text_input("ask anything related to the invoice")
submit_button=st.button("Submit")
if submit_button and user_question:
response=get_response(b64_image,user_question)
st.write(response)




if __name__=="__main__":
main()

0 comments on commit 572111d

Please sign in to comment.