xnetba commited on
Commit
10462cf
1 Parent(s): bcd16ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -11
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import base64
2
-
3
  import streamlit as st
4
  from streamlit_chat import message
5
  from streamlit_extras.colored_header import colored_header
6
-
7
  from backend import QnASystem
8
  from schema import TransformType, EmbeddingTypes, IndexerType, BotType
9
 
@@ -14,7 +12,6 @@ st.set_page_config(page_title="PDFChat - An LLM-powered experimentation app")
14
  if "qna_system" not in st.session_state:
15
  st.session_state.qna_system = QnASystem()
16
 
17
-
18
  def show_pdf(f):
19
  f.seek(0)
20
  base64_pdf = base64.b64encode(f.read()).decode('utf-8')
@@ -22,12 +19,10 @@ def show_pdf(f):
22
  f'type="application/pdf"></iframe>'
23
  st.markdown(pdf_display, unsafe_allow_html=True)
24
 
25
-
26
  def model_settings():
27
  kwargs["temperature"] = st.slider("Temperature", max_value=1.0, min_value=0.0)
28
  kwargs["max_tokens"] = st.number_input("Max Token", min_value=0, value=512)
29
 
30
-
31
  st.title("PDF Question and Answering")
32
 
33
  tab1, tab2, tab3 = st.tabs(["Upload and Ingest PDF", "Ask", "Show PDF"])
@@ -53,7 +48,7 @@ with st.sidebar:
53
  api_key = st.text_input("Hugging Face API Key", placeholder="hg-...", type="password")
54
  if not api_key.startswith('hg-'):
55
  st.warning('Please enter your HuggingFace API key!', icon='⚠')
56
- huggingface_model = st.selectbox("Choose Model", options=["google/flan-t5-xl", "huggingface/model2", "huggingface/model3"])
57
  model_settings()
58
  case EmbeddingTypes.COHERE:
59
  api_key = st.text_input("Cohere API Key", placeholder="...", type="password")
@@ -92,14 +87,12 @@ with tab1:
92
  st.session_state.qna_system.build_chain(transform_type=text_transform, embedding_type=selected_model,
93
  indexer_type=vector_indexer, **kwargs)
94
 
95
-
96
  def generate_response(prompt):
97
  if prompt and uploaded_file:
98
  response = st.session_state.qna_system.ask_question(prompt)
99
  return response.get("answer", response.get("result", "")), response.get("source_documents")
100
  return "", []
101
 
102
-
103
  with tab2:
104
  if not uploaded_file:
105
  st.warning("Please upload PDF", icon='⚠')
@@ -128,12 +121,10 @@ with tab2:
128
  response_container = st.container()
129
  response = ""
130
 
131
-
132
  def get_text():
133
  input_text = st.text_input("You: ", "", key="input")
134
  return input_text
135
 
136
-
137
  with input_container:
138
  user_input = get_text()
139
  if st.button("Clear"):
@@ -168,4 +159,4 @@ with tab3:
168
  elif uploaded_file:
169
  st.warning("Feature not enabled.", icon='⚠')
170
  else:
171
- st.warning("Please upload PDF", icon='⚠')
 
1
  import base64
 
2
  import streamlit as st
3
  from streamlit_chat import message
4
  from streamlit_extras.colored_header import colored_header
 
5
  from backend import QnASystem
6
  from schema import TransformType, EmbeddingTypes, IndexerType, BotType
7
 
 
12
  if "qna_system" not in st.session_state:
13
  st.session_state.qna_system = QnASystem()
14
 
 
15
  def show_pdf(f):
16
  f.seek(0)
17
  base64_pdf = base64.b64encode(f.read()).decode('utf-8')
 
19
  f'type="application/pdf"></iframe>'
20
  st.markdown(pdf_display, unsafe_allow_html=True)
21
 
 
22
  def model_settings():
23
  kwargs["temperature"] = st.slider("Temperature", max_value=1.0, min_value=0.0)
24
  kwargs["max_tokens"] = st.number_input("Max Token", min_value=0, value=512)
25
 
 
26
  st.title("PDF Question and Answering")
27
 
28
  tab1, tab2, tab3 = st.tabs(["Upload and Ingest PDF", "Ask", "Show PDF"])
 
48
  api_key = st.text_input("Hugging Face API Key", placeholder="hg-...", type="password")
49
  if not api_key.startswith('hg-'):
50
  st.warning('Please enter your HuggingFace API key!', icon='⚠')
51
+ kwargs["model_name"] = st.selectbox("Choose Model", options=["google/flan-t5-xl"])
52
  model_settings()
53
  case EmbeddingTypes.COHERE:
54
  api_key = st.text_input("Cohere API Key", placeholder="...", type="password")
 
87
  st.session_state.qna_system.build_chain(transform_type=text_transform, embedding_type=selected_model,
88
  indexer_type=vector_indexer, **kwargs)
89
 
 
90
  def generate_response(prompt):
91
  if prompt and uploaded_file:
92
  response = st.session_state.qna_system.ask_question(prompt)
93
  return response.get("answer", response.get("result", "")), response.get("source_documents")
94
  return "", []
95
 
 
96
  with tab2:
97
  if not uploaded_file:
98
  st.warning("Please upload PDF", icon='⚠')
 
121
  response_container = st.container()
122
  response = ""
123
 
 
124
  def get_text():
125
  input_text = st.text_input("You: ", "", key="input")
126
  return input_text
127
 
 
128
  with input_container:
129
  user_input = get_text()
130
  if st.button("Clear"):
 
159
  elif uploaded_file:
160
  st.warning("Feature not enabled.", icon='⚠')
161
  else:
162
+ st.warning("Please upload PDF", icon='⚠')