Download app.py from Rajagopal/try556a: direct link, hf CLI and curl.
- Browser
- Download file 3.44 kB
-
https://huggingface.co/spaces/Rajagopal/try556a/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rajagopal/try556a/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rajagopal/try556a/resolve/main/app.py
3.44 kB
| 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) | |
| # Run the chain only specifying the input variable. | |
| 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) | |
| # Run the chain only specifying the input variable. | |
| 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) | |
| # Run the chain only specifying the input variable. | |
| 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) | |
| # Run the chain only specifying the input variable. | |
| st.write(chain.run(yourquestion)) | |