Skip to content

Commit

Permalink
tutorial105
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Jul 20, 2024
1 parent 49fd3c6 commit bd6eb17
Show file tree
Hide file tree
Showing 62 changed files with 99 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tutorial105/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from pytubefix import YouTube
from pytubefix.cli import on_progress
url = "https://www.youtube.com/watch?v=j7_L3w4vOJk&t=25s"
yt = YouTube(url)
print(yt.title)
ys = yt.streams.get_highest_resolution()
ys.download(filename="output.mp4")
Binary file added tutorial105/frame0000.png
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 tutorial105/frame0001.png
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 tutorial105/frame0002.png
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 tutorial105/frame0003.png
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 tutorial105/frame0004.png
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 tutorial105/frame0005.png
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 tutorial105/frame0006.png
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 tutorial105/frame0007.png
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 tutorial105/frame0008.png
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 tutorial105/frame0009.png
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 tutorial105/frame0010.png
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 tutorial105/frame0011.png
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 tutorial105/frame0012.png
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 tutorial105/frame0013.png
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 tutorial105/frame0014.png
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 tutorial105/frame0015.png
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 tutorial105/frame0016.png
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 tutorial105/frame0017.png
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 tutorial105/frame0018.png
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 tutorial105/frame0019.png
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 tutorial105/frame0020.png
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 tutorial105/frame0021.png
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 tutorial105/frame0022.png
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 tutorial105/frame0023.png
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 tutorial105/frame0024.png
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 tutorial105/frame0025.png
Binary file added tutorial105/frame0026.png
Binary file added tutorial105/frame0027.png
Binary file added tutorial105/frame0028.png
Binary file added tutorial105/frame0029.png
Binary file added tutorial105/frame0030.png
Binary file added tutorial105/frame0031.png
Binary file added tutorial105/frame0032.png
Binary file added tutorial105/frame0033.png
Binary file added tutorial105/frame0034.png
Binary file added tutorial105/frame0035.png
Binary file added tutorial105/frame0036.png
Binary file added tutorial105/frame0037.png
Binary file added tutorial105/frame0038.png
Binary file added tutorial105/frame0039.png
Binary file added tutorial105/frame0040.png
Binary file added tutorial105/frame0041.png
Binary file added tutorial105/frame0042.png
Binary file added tutorial105/frame0043.png
Binary file added tutorial105/frame0044.png
Binary file added tutorial105/frame0045.png
Binary file added tutorial105/frame0046.png
Binary file added tutorial105/frame0047.png
Binary file added tutorial105/frame0048.png
Binary file added tutorial105/frame0049.png
Binary file added tutorial105/frame0050.png
Binary file added tutorial105/frame0051.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added tutorial105/index/chroma.sqlite3
Binary file not shown.
Binary file added tutorial105/output.mp4
Binary file not shown.
9 changes: 9 additions & 0 deletions tutorial105/processvideo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from moviepy.editor import *
import os
cwd=os.getcwd()

clip = VideoFileClip(r"C:\Users\welcome\OneDrive\Documents\GitHub\LLMtutorial\tutorial105\output.mp4")
clip.write_images_sequence(
os.path.join(cwd, "frame%04d.png"), fps=.2 #configure this for controlling frame rate.
)

82 changes: 82 additions & 0 deletions tutorial105/rag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
from langchain_openai import ChatOpenAI
from langchain.chains import RetrievalQA
import io,glob,base64,sys
from langchain.schema.document import Document
import uuid
from langchain_community.vectorstores import Chroma
from langchain_experimental.open_clip import OpenCLIPEmbeddings
from PIL import Image
from langchain.schema.messages import HumanMessage
import streamlit as st
llm=ChatOpenAI(model="gpt-4o")
# Create chroma
vectorstore = Chroma(
collection_name="mm_rag_clip_photos", persist_directory=os.getcwd()+"/index",embedding_function=OpenCLIPEmbeddings()
)

# def image2base64(ip):
# with Image.open(ip) as image:
# buffer=io.BytesIO()
# image.save(buffer,format=image.format)
# img_str=base64.b64encode(buffer.getvalue())
# return img_str.decode("utf-8")

# cwd=os.getcwd()
# files=glob.glob(cwd+"/*.png")
# imgs=[]
# imgs_summary=[]

# for file in files:
# image_str=image2base64(file)
# response=llm.invoke(
# [
# HumanMessage(
# content=[
# {"type":"text","text":"please give a summary of the image provided , be descriptive and smart"},
# {"type":"image_url","image_url":
# {
# "url":f"data:image/png;base64,{image_str}"

# },
# },
# ]
# )
# ]
# )
# imgs.append(image_str)
# imgs_summary.append(response.content)
# print(imgs_summary)
# documents=[]
# for e,s in zip(imgs,imgs_summary):
# i=str(uuid.uuid4())
# doc=Document(
# page_content=s,
# metadata={
# "id":i,
# "type":"image",
# "original_content":e
# }
# )
# documents.append(doc)
# vectorstore.add_documents(documents=documents)
retriver=vectorstore.as_retriever()
chain=RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriver
)
# response=chain.invoke("describe all the characters you found here")
# print(response)

response1=vectorstore.similarity_search("describe fight scenes",k=3)
context=""
ri=[]
for xx in response1:
if xx.metadata["type"] =="image":
context +='[image]'+xx.page_content
ri.append(xx.metadata["original_content"])

print(context)
image_output=ri[0].encode("utf-8")
st.image(base64.b64decode(image_output))
Binary file added tutorial105/tutorial105.pptx
Binary file not shown.

0 comments on commit bd6eb17

Please sign in to comment.