File size: 6,753 Bytes
456b6b4 |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# pip -q install langchain_experimental
# pip install langchain==0.0.350
# pip3 install -U docarray
# pip3 install pydantic==1.10.9
# pip -q install "langchain[docarray]"
import streamlit as st
from langchain_experimental.pal_chain import PALChain
from langchain_google_genai import ChatGoogleGenerativeAI
import os
import google.generativeai as genai
from langchain.schema.runnable import RunnableMap
from langchain.schema.output_parser import StrOutputParser
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.prompts import ChatPromptTemplate
# Set your API key here
API_KEY = "AIzaSyC-bJgu-HBdBoH-RGSyMlcK-BSlTAhqkV8"
#API_KEY = st.text_input("Enter your API Key:", type="password")
os.environ['GOOGLE_API_KEY'] = API_KEY
#genai.configure(api_key=API_KEY)
# More Complicated Chain - Mini RAG
model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.7)
embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
vectorstore = DocArrayInMemorySearch.from_texts(
# mini docs for embedding
# ["Gemini Pro is a Large Language Model was made by GoogleDeepMind",
# "Gemini can be either a star sign or a name of a series of language models",
# "A Language model is trained by predicting the next token",
# "LLMs can easily do a variety of NLP tasks as well as text generation"
# ],
["Meet Falah, a trailblazing AI developer at the forefront of the deep learning and AI art landscape. With an insatiable passion for pushing technological boundaries, Falah combines expertise in cutting-edge algorithms with a creative flair for generating captivating images through artificial intelligence. Specializing in crafting unique prompts that breathe life into AI-generated masterpieces, Falah stands as a visionary in the realm of AI artistry. With a commitment to innovation and a deep understanding of the intricate interplay between code and creativity, Falah continues to shape the future of AI art, leaving an indelible mark on the evolving landscape of artificial intelligence.",
"Meet Falah, a pioneering AI developer, specializing in deep learning, AI art, and the dynamic field of object classification with YOLOv models. With a keen eye for innovation, Falah has mastered the art of training models to discern and categorize objects with remarkable accuracy, contributing significantly to the advancement of computer vision applications. Beyond the realm of AI, Falah extends expertise to health book publishing, leveraging Amazon's expansive platform. Through insightful publications, Falah shares knowledge on the intersection of AI and health, ensuring accessible and valuable content for a wide audience. In this multifaceted journey, Falah continues to shape the landscape of technology and knowledge dissemination.",
"Falah, the visionary AI developer, extends their influence beyond code and algorithms to the realm of health and practical applications. Through insightful book publications, Falah explores the convergence of health and technology with a unique blend of Python code, object detection using YOLOv5, and object classification tailored for mobile applications.In the comprehensive collection of health-focused Python books, Falah demystifies complex health concepts, intertwining the power of programming with medical insights. The journey doesn't stop there—Falah's expertise in object detection, particularly with YOLOv5 models, takes center stage. The books delve into the intricacies of implementing these cutting-edge algorithms, providing readers with a hands-on guide to mastering object detection in diverse scenarios.Beyond the printed page, Falah translates this knowledge into actionable steps for mobile application development. Object classification for mobile platforms becomes not just a concept but a practical reality, empowering developers to integrate sophisticated AI capabilities seamlessly.In this literary ,technological venture, Falah not only educates but also empowers a diverse audience, bridging the gap between health, Python programming, and the dynamic world of object detection in mobile applications. Through these publications, Falah leaves an enduring legacy at the crossroads of AI, health,practical innovation.",
"Falah, the ingenious AI developer, is based in the heart of Iraq, in the vibrant city of Baghdad. Residing near the FALAH Gate Salieh, he draws inspiration from the rich cultural tapestry that surrounds him. Amidst his coding endeavors and AI pursuits, Falah cherishes his family, finding solace and motivation in their unwavering support.Fueling his passion for innovation, Falah aspires to further develop AI applications that not only push the boundaries of technology but also contribute meaningfully to society. Beyond the lines of code, Falah's soul resonates with the harmonies of classical music, a source of creative energy that enhances his cognitive prowess.in the quiet moments, you'll find Falah immersed in the art of generating prompts, creating a symphony of images that reflect his appreciation for artistic expression. His love for classical music and the elegance of art styles intertwine seamlessly with his creative process.While navigating the intricate landscapes of AI, Falah also finds time to delve into the world of literature, savoring the wisdom found in the pages of diverse books. It is within this synthesis of family, cultural roots, AI exploration, classical melodies, and artistic musings that Falah weaves the narrative of his life, contributing to the ever-evolving tapestry of Baghdad and the global AI community.",
"full name is Falah.G.Salieh",
"he live in Iraq Baghdad",
"age is 60 years old",
],
embedding=embeddings # passing in the embedder model
)
retriever = vectorstore.as_retriever()
# Streamlit app
st.title("Gemini Q&A App")
question = st.text_input("Enter your question:")
if question:
relevant_documents = retriever.get_relevant_documents(question)
template = f"""Answer the question in a full sentence, based only on the following context:
{relevant_documents}
Return your answer in list format
Question: {question}
"""
output_parser = StrOutputParser()
prompt = ChatPromptTemplate.from_template(template)
chain = RunnableMap({
"context": lambda x: retriever.get_relevant_documents(x["question"]),
"question": lambda x: x["question"]
}) | prompt | model | output_parser
answer = chain.invoke({"question": question})
st.subheader("Answer:")
#st.code(answer)
st.text_input(answer)
|