Skip to content

Commit

Permalink
tutorial43
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Feb 22, 2024
1 parent 3311c14 commit 19e65d4
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
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/i61Ik9aH08Q")
loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/sUUTzdfiNZg")
docs=loader.load()
print(docs)
with io.open("transcript.txt","w",encoding="utf-8")as f1:
Expand Down
Binary file not shown.
Binary file added tutorial43/__pycache__/downloadvideo.cpython-311.pyc
Binary file not shown.
Binary file added tutorial43/__pycache__/genvideo.cpython-311.pyc
Binary file not shown.
Binary file added tutorial43/inv1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorial43/inv2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions tutorial43/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-4-vision-preview",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("CONVA 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()
Binary file added tutorial43/tutorial43.pptx
Binary file not shown.

0 comments on commit 19e65d4

Please sign in to comment.