|
import streamlit as st |
|
from langchain import OpenAI, PromptTemplate, LLMChain |
|
from langchain.text_splitter import CharacterTextSplitter |
|
from langchain.chains.mapreduce import MapReduceChain |
|
from langchain.prompts import PromptTemplate |
|
from langchain.chat_models import AzureChatOpenAI |
|
from langchain.chains.summarize import load_summarize_chain |
|
from langchain.chains import AnalyzeDocumentChain |
|
from PyPDF2 import PdfReader |
|
from langchain.document_loaders import TextLoader |
|
from langchain.indexes import VectorstoreIndexCreator |
|
from langchain.document_loaders import PyPDFLoader |
|
import os |
|
import openai |
|
|
|
|
|
import os |
|
|
|
|
|
os.environ["OPENAI_API_TYPE"] = "azure" |
|
os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview" |
|
|
|
openai.api_type = "azure" |
|
openai.api_base = "https://embeddinguseopenai.openai.azure.com/" |
|
openai.api_version = "2023-03-15-preview" |
|
openai.api_key = os.environ["OPENAI_API_KEY"] |
|
|
|
|
|
|
|
|
|
|
|
st.title("Wipro demo with azure cognitive 2 ") |
|
|
|
|
|
atemprature = st.slider('Fact vs Creative?', 0, 10, 1) |
|
atemprature = atemprature / 10.0 |
|
|
|
|
|
yourquestion = st.text_input('Your Question', 'First identify the indicators required as per EFRAG Environmental document. List these indicators. For each of these indicators, find out how Wipro is performing.') |
|
st.write('Your input is ', yourquestion) |
|
|
|
|
|
|
|
|
|
|
|
if st.button("Ask Questions "): |
|
template = """ |
|
You are an AI assistant. |
|
{concept} |
|
""" |
|
|
|
response = openai.ChatCompletion.create( |
|
engine="gpt-35-turbo", |
|
messages = [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":yourquestion}], |
|
temperature=atemprature, |
|
max_tokens=800, |
|
top_p=1, |
|
frequency_penalty=0, |
|
presence_penalty=0, |
|
stop=None) |
|
|
|
|
|
st.write(response) |
|
|
|
|
|
if st.button("Ask Questions Simplify "): |
|
template = """ |
|
You are an AI assistant. |
|
{concept} |
|
""" |
|
|
|
response = openai.ChatCompletion.create( |
|
engine="gpt-35-turbo", |
|
messages = [{"role":"system","content":"You are an AI assistant that helps people find information. Please explain the information like i am a five."},{"role":"user","content":yourquestion}], |
|
temperature=0, |
|
max_tokens=800, |
|
top_p=1, |
|
frequency_penalty=0, |
|
presence_penalty=0, |
|
stop=None) |
|
|
|
|
|
st.write(response) |
|
|
|
if st.button("Ask trying here "): |
|
template = """ |
|
You are an expert on topics of Sustainability, Climate action and UN Sustainable Development Goals. |
|
Explain the concept of {concept} like i am a five |
|
""" |
|
|
|
prompt = PromptTemplate( |
|
input_variables=["concept"], |
|
template=template, |
|
) |
|
|
|
|
|
from langchain.chains import LLMChain |
|
chain = LLMChain(llm=llm, prompt=prompt) |
|
|
|
|
|
st.write(chain.run(yourquestion)) |
|
|
|
|
|
|
|
if st.button("Ask Hindi "): |
|
template = """ |
|
You are an expert on topics of Sustainability, Climate action and UN Sustainable Development Goals. |
|
Explain the concept of {concept} in Hindi |
|
""" |
|
|
|
prompt = PromptTemplate( |
|
input_variables=["concept"], |
|
template=template, |
|
) |
|
|
|
|
|
from langchain.chains import LLMChain |
|
chain = LLMChain(llm=llm, prompt=prompt) |
|
|
|
|
|
st.write(chain.run(yourquestion)) |
|
|