Skip to content

Commit

Permalink
tutorial117
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Oct 30, 2024
1 parent 0500a00 commit 79fdaa3
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 34 deletions.
File renamed without changes.
47 changes: 22 additions & 25 deletions tutorial117/main.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
from langchain_community.document_loaders import RedditPostsLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_openai import ChatOpenAI,OpenAIEmbeddings
from langchain_chroma import Chroma
from langchain_community.vectorstores.utils import filter_complex_metadata
from langchain.chains.question_answering import load_qa_chain
import io
from langchain_core.documents import Document
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
llm=ChatOpenAI(model="gpt-4o")
loader=RedditPostsLoader(
client_id="7aJt9CuSBwg4unyMjk8kZg",
client_secret="v1UUmCA4VHU-0MLzzR11pHYv7dRzXA",
user_agent="Sad_Mud_4484",
search_queries=["IndiaCricket"],
mode= "subreddit",
number_posts= 100
)
docs=loader.load()
ts=RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=20)
sd=ts.split_documents(docs)
vs=Chroma.from_documents(filter_complex_metadata(sd),embedding=OpenAIEmbeddings(),persist_directory="./vs")
vs=Chroma(persist_directory="./vs",embedding_function=OpenAIEmbeddings())
retriever=vs.as_retriever(k=5)
match_docs=retriever.invoke("india vs newzeland test")
print(match_docs)
chain=load_qa_chain(llm=llm,chain_type="stuff")
response=chain.run(input_documents=match_docs,question="how Washington Sundar performed?")
print(response)
import os,glob
cwd=os.getcwd()
files=glob.glob(cwd+"/*.txt")
documents=[]
for file in files:
with io.open(file,"r",encoding="utf-8")as f1:
data=f1.read()
f1.close()
documents.append(Document(page_content=data,metadata={"title":file.split("\\")[-1]}))
# print(documents)

prompt=ChatPromptTemplate.from_template("Summarize this content with little bullet :{context}")
chain=create_stuff_documents_chain(llm,prompt)
response=chain.invoke({"context":documents})
print(response)


4 changes: 4 additions & 0 deletions tutorial117/news1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
QuantumTech Inc. Unveils Revolutionary Quantum Processor Expected to Transform AI
New York, October 30, 2024 — QuantumTech Inc. announced a major advancement in quantum computing with the introduction of its latest processor, the "Q-Pro 2025." According to the company, this breakthrough promises to process calculations far faster than traditional supercomputers, opening doors to unprecedented applications in artificial intelligence, medicine, and environmental modeling.

"Q-Pro 2025 will help address some of the world’s most complex challenges," said Dr. Lisa Morgan, CEO of QuantumTech. "From advanced AI algorithms to drug discovery, our quantum processor will redefine what’s possible." Industry experts are calling it a milestone that may push other tech firms to intensify their own quantum research, though widespread commercial use could still be several years away
4 changes: 4 additions & 0 deletions tutorial117/news2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
New Biodegradable Solar Panels Could Be Key to Truly Green Energy
Washington D.C., October 30, 2024 — Scientists at the National Renewable Energy Laboratory (NREL) have unveiled the world’s first fully biodegradable solar panels, offering a new solution to reduce environmental waste in renewable energy. Traditional solar panels are challenging to recycle, often containing harmful chemicals, while these new panels are made from organic materials that can naturally decompose.

Dr. Emily Zhao, who led the NREL team, stated, "This technology allows us to harness solar energy sustainably. We’re excited about the environmental benefits as we work toward mass production." The research team plans to scale up production in the coming year, with hopes that the innovation could lead to greener energy on a global scale.
4 changes: 4 additions & 0 deletions tutorial117/news3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Tokyo’s New AI Traffic System Aims to Reduce Congestion and Emissions
Tokyo, October 30, 2024 — In a bold step toward sustainable urban planning, the City of Tokyo has announced plans to launch an AI-driven smart traffic management system next year. Using real-time data from vehicles, traffic cameras, and sensors, the AI system will optimize traffic flow, reduce delays, and improve public transportation schedules.

"With this system, we aim to make daily commuting faster and more efficient, while also reducing the city’s carbon emissions," explained Yuki Tanaka, head of Tokyo’s urban planning department. The AI traffic system is expected to be implemented in phases, starting in high-traffic areas. Once fully operational, it’s anticipated to enhance air quality and make Tokyo’s streets safer for all residents.
6 changes: 0 additions & 6 deletions tutorial117/prompt.txt

This file was deleted.

Binary file added tutorial117/tutorial117.pptx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file removed tutorial117/vs/chroma.sqlite3
Binary file not shown.
5 changes: 3 additions & 2 deletions tutorial2/single_url.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from langchain.document_loaders import youtube
#from langchain.document_loaders import youtube
from langchain_community.document_loaders import YoutubeLoader
import io

loader=youtube.YoutubeLoader.from_youtube_url("https://youtu.be/7iEZ6OrKk6Q")
loader=YoutubeLoader.from_youtube_url("https://youtu.be/bjHQZ27qe3g")
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.

0 comments on commit 79fdaa3

Please sign in to comment.