Spaces:
Build error

t6pankaj commited on
Commit
3bb2da3
·
1 Parent(s): 5ed785f

Adding the chat file

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +20 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import os to handle environment variables
2
+ #
3
+ # To run this app
4
+ #
5
+ # streamlit run <path to this file, for example, rag\streamlit_app_basic.py>
6
+ #
7
+ import os
8
+ from dotenv import load_dotenv
9
+ import streamlit as st
10
+ from langchain_openai import AzureChatOpenAI
11
+ from langchain_core.messages import HumanMessage
12
+ from langchain_community.callbacks import get_openai_callback
13
+
14
+ load_dotenv()
15
+
16
+ azure_config = {
17
+ "AZURE_OPENAI_ENDPOINT": os.getenv("AZURE_OPENAI_ENDPOINT"),
18
+ "AZURE_OPENAI_MODEL_DEPLOYMENT_NAME": os.getenv("AZURE_OPENAI_MODEL_DEPLOYMENT_NAME"),
19
+ "AZURE_OPENAI_MODEL_NAME": os.getenv("AZURE_OPENAI_MODEL_NAME"),
20
+ "AZURE_OPENAI_API_KEY": os.getenv("AZURE_OPENAI_API_KEY"),
21
+ "AZURE_OPENAI_API_VERSION": os.getenv("AZURE_OPENAI_API_VERSION")
22
+ }
23
+
24
+ st.subheader("EY GenAI class: GenAI chatbot Demo")
25
+
26
+ with st.sidebar:
27
+ os.environ["AZURE_OPENAI_ENDPOINT"] = azure_config["AZURE_OPENAI_ENDPOINT"]
28
+ #openai_api_key = st.text_input("OpenAI API Key", type="password")
29
+ #os.environ["AZURE_OPENAI_API_KEY"] = azure_config["api-key"]
30
+ #"[Get an Azure OpenAI API key from 'Keys and Endpoint' in Azure Portal](https://portal.azure.com/#blade/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/OpenAI)"
31
+
32
+ def generate_response(input_text):
33
+
34
+ llm = AzureChatOpenAI(temperature=0,
35
+ api_key=azure_config["AZURE_OPENAI_API_KEY"],
36
+ openai_api_version=azure_config["AZURE_OPENAI_API_VERSION"],
37
+ azure_endpoint=azure_config["AZURE_OPENAI_ENDPOINT"],
38
+ model=azure_config["AZURE_OPENAI_MODEL_DEPLOYMENT_NAME"],
39
+ validate_base_url=False)
40
+
41
+ message = HumanMessage(
42
+ content=input_text
43
+ )
44
+
45
+ with get_openai_callback() as cb:
46
+ st.info(llm([message]).content) # chat model output
47
+ st.info(cb) # callback output (like cost)
48
+
49
+
50
+ user_question = st.text_input("Ask any question. Press enter to submit", key="user_question")
51
+ if user_question:
52
+ generate_response(user_question)
requirements.txt ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain-openai
2
+ langchain-community
3
+ langchain-text-splitters
4
+ chromadb
5
+ langchain
6
+ beautifulsoup4
7
+ pypdf
8
+ wikipedia
9
+ plotly
10
+ ragas
11
+ tqdm
12
+ datasets
13
+ renumics-spotlight
14
+ python-dotenv
15
+ openai
16
+ streamlit
17
+ dotted-dict
18
+ PyPDF2
19
+ matplotlib
20
+ seaborn