phoen1x commited on
Commit
bc8f772
1 Parent(s): 931f95f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -75
app.py CHANGED
@@ -104,6 +104,7 @@
104
 
105
 
106
  import os
 
107
  import gradio as gr
108
  from PyPDF2 import PdfReader
109
  from langchain.text_splitter import CharacterTextSplitter
@@ -115,7 +116,9 @@ from langchain.chains import ConversationalRetrievalChain
115
  from huggingface_hub import InferenceClient
116
 
117
  # Set the Hugging Face Hub API token
118
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets['huggingface_token']
 
 
119
 
120
  # Initialize the InferenceClient
121
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
@@ -176,79 +179,35 @@ def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=256
176
  yield output
177
  return output
178
 
179
- def main(pdf_docs):
180
- # get pdf text
181
- raw_text = get_pdf_text(pdf_docs)
182
-
183
- # get the text chunks
184
- text_chunks = get_text_chunks(raw_text)
185
-
186
- # create vector store
187
- vectorstore = get_vectorstore(text_chunks)
188
-
189
- # create conversation chain
190
- conversation_chain = get_conversation_chain(vectorstore)
191
-
192
- additional_inputs=[
193
- gr.Textbox(
194
- label="System Prompt",
195
- max_lines=1,
196
- interactive=True,
197
- ),
198
- gr.Slider(
199
- label="Temperature",
200
- value=0.9,
201
- minimum=0.0,
202
- maximum=1.0,
203
- step=0.05,
204
- interactive=True,
205
- info="Higher values produce more diverse outputs",
206
- ),
207
- gr.Slider(
208
- label="Max new tokens",
209
- value=256,
210
- minimum=0,
211
- maximum=1048,
212
- step=64,
213
- interactive=True,
214
- info="The maximum numbers of new tokens",
215
- ),
216
- gr.Slider(
217
- label="Top-p (nucleus sampling)",
218
- value=0.90,
219
- minimum=0.0,
220
- maximum=1,
221
- step=0.05,
222
- interactive=True,
223
- info="Higher values sample more low-probability tokens",
224
- ),
225
- gr.Slider(
226
- label="Repetition penalty",
227
- value=1.2,
228
- minimum=1.0,
229
- maximum=2.0,
230
- step=0.05,
231
- interactive=True,
232
- info="Penalize repeated tokens",
233
- )
234
- ]
235
-
236
- examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
237
- ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
238
- ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
239
- ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
240
- ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
241
- ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
242
- ]
243
-
244
- gr.ChatInterface(
245
- fn=generate,
246
- chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
247
- additional_inputs=additional_inputs,
248
- title="Mixtral 46.7B",
249
- examples=examples,
250
- concurrency_limit=20,
251
- ).launch(show_api= True)
252
 
253
  if __name__ == "__main__":
254
- main([])
 
104
 
105
 
106
  import os
107
+ import streamlit as st
108
  import gradio as gr
109
  from PyPDF2 import PdfReader
110
  from langchain.text_splitter import CharacterTextSplitter
 
116
  from huggingface_hub import InferenceClient
117
 
118
  # Set the Hugging Face Hub API token
119
+ hf_token = st.secrets['MixtralPDFChat']
120
+
121
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = hf_token
122
 
123
  # Initialize the InferenceClient
124
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
 
179
  yield output
180
  return output
181
 
182
+ def main():
183
+ st.title("PDF Chatbot")
184
+
185
+ # Upload PDF files
186
+ pdf_docs = st.file_uploader("Upload PDF files", type=['pdf'], accept_multiple_files=True)
187
+
188
+ if pdf_docs:
189
+ # get pdf text
190
+ raw_text = get_pdf_text(pdf_docs)
191
+
192
+ # get the text chunks
193
+ text_chunks = get_text_chunks(raw_text)
194
+
195
+ # create vector store
196
+ vectorstore = get_vectorstore(text_chunks)
197
+
198
+ # create conversation chain
199
+ conversation_chain = get_conversation_chain(vectorstore)
200
+
201
+ def chat_interface(user_input):
202
+ response = next(generate(user_input, [], "System Prompt"))
203
+ return response
204
+
205
+ st.subheader("Chat Interface")
206
+ user_input = st.text_input("Ask a question:")
207
+ if user_input:
208
+ response = chat_interface(user_input)
209
+ st.write("Bot's Response:")
210
+ st.write(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
  if __name__ == "__main__":
213
+ main()