Rehman1603 commited on
Commit
fd67255
·
verified ·
1 Parent(s): 9e73cff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,10 +1,12 @@
1
  import gradio as gr
 
2
  import os
3
- from langchain import PromptTemplate, LLMChain
 
4
  from langchain_together import Together
 
5
  import pdfplumber
6
-
7
- # Set the API key with double quotes
8
  os.environ['TOGETHER_API_KEY'] = "c2f52626b97118b71c0c36f66eda4f5957c8fc475e760c3d72f98ba07d3ed3b5"
9
 
10
  def extract_text_from_pdf(pdf_file, max_pages=16):
@@ -58,12 +60,19 @@ def ChatBot(history, document, question):
58
  if question_lower in greetings or any(question_lower.startswith(greeting) for greeting in greetings):
59
  return history + [("User", question), ("Bot", "Hello! How can I assist you with the document today?")]
60
 
 
61
  text = extract_text_from_pdf(document)
 
 
62
  response = Bot(text, question)
 
 
63
  history.append(("User", question))
64
  history.append(("Bot", response))
 
65
  return history
66
 
 
67
  with gr.Blocks() as iface:
68
  chatbot = gr.Chatbot()
69
  document = gr.File(label="Upload PDF Document", type="filepath")
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  import os
4
+ from langchain import PromptTemplate
5
+ from langchain import LLMChain
6
  from langchain_together import Together
7
+ import re
8
  import pdfplumber
9
+ # Set the API key
 
10
  os.environ['TOGETHER_API_KEY'] = "c2f52626b97118b71c0c36f66eda4f5957c8fc475e760c3d72f98ba07d3ed3b5"
11
 
12
  def extract_text_from_pdf(pdf_file, max_pages=16):
 
60
  if question_lower in greetings or any(question_lower.startswith(greeting) for greeting in greetings):
61
  return history + [("User", question), ("Bot", "Hello! How can I assist you with the document today?")]
62
 
63
+ # Extract text from the uploaded PDF document
64
  text = extract_text_from_pdf(document)
65
+
66
+ # Generate the bot response based on the question and extracted text
67
  response = Bot(text, question)
68
+
69
+ # Update chat history with the user's question and bot's response
70
  history.append(("User", question))
71
  history.append(("Bot", response))
72
+
73
  return history
74
 
75
+ # Set up the Gradio interface using Blocks
76
  with gr.Blocks() as iface:
77
  chatbot = gr.Chatbot()
78
  document = gr.File(label="Upload PDF Document", type="filepath")