KushJaggi commited on
Commit
c7552d0
·
1 Parent(s): 526fa04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -66
app.py CHANGED
@@ -65,18 +65,6 @@ css = """
65
  margin-bottom: 10px;
66
  }
67
 
68
- .repo-id {
69
- margin-bottom: 10px;
70
- }
71
-
72
- .langchain-status {
73
- margin-bottom: 10px;
74
- }
75
-
76
- .load-pdf {
77
- margin-bottom: 10px;
78
- }
79
-
80
  .chatbot {
81
  height: 350px;
82
  border: 1px solid #ccc;
@@ -109,61 +97,29 @@ title = """
109
  </div>
110
  """
111
 
112
-
113
- def pdf_changes(inputs, outputs):
114
- """Updates the text of the langchain status textbox."""
115
- pdf_doc = inputs["pdf_doc"]
116
- repo_id = inputs["repo_id"]
117
-
118
- langchain_status.update_text(f"Loading PDF to langchain...")
119
-
120
- # Load the PDF to langchain
121
- langchain.load_pdf(pdf_doc, repo_id)
122
-
123
- langchain_status.update_text(f"PDF loaded to langchain.")
124
-
125
-
126
- def add_text(inputs, outputs):
127
- """Adds text to the chatbot."""
128
- chatbot = inputs["chatbot"]
129
- question = inputs["question"]
130
-
131
- # Add the user question to the chatbot
132
- chatbot.add_user_message(question)
133
-
134
- # Get the response from the langchain chatbot
135
- response = langchain.get_response(question)
136
-
137
- # Add the bot response to the chatbot
138
- chatbot.add_bot_message(response)
139
-
140
-
141
- # Create the chatbot
142
- chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
143
-
144
- # Create the langchain object
145
- langchain = gr.Langchain()
146
-
147
- # Create the UI
148
  with gr.Blocks(css=css) as demo:
149
- with gr.Column(elem_id="col-container"):
150
- gr.HTML(title)
151
-
152
- with gr.Column():
153
- pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
154
- repo_id = gr.Dropdown(label="LLM", choices=["google/flan-ul2", "OpenAssistant/oasst-sft-1-pythia-12b", "bigscience/bloomz"], value="google/flan-ul2")
155
- with gr.Row():
156
- langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
157
- load_pdf = gr.Button("Load pdf to langchain")
158
- chatbot.style(height=350)
159
-
160
- question = gr.Textbox(label="Question", placeholder="Type your Question and hit Enter ")
161
- submit_btn = gr.Button("Send message")
162
-
163
- # Respond to events
164
- load_pdf.click(pdf_changes, inputs=[pdf_doc, repo_id], outputs=[langchain_status], queue=False)
165
- question.submit(add_text, [chatbot, question], [chatbot, question]).then(bot, chatbot, chatbot)
166
- submit_btn.click(add_text, [chatbot, question], [chatbot, question]).then(bot, chatbot, chatbot)
 
 
 
 
167
 
168
  # Start the demo
169
  demo.show(True)
 
65
  margin-bottom: 10px;
66
  }
67
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  .chatbot {
69
  height: 350px;
70
  border: 1px solid #ccc;
 
97
  </div>
98
  """
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  with gr.Blocks(css=css) as demo:
101
+ with gr.Column(elem_id="col-container"):
102
+ gr.HTML(title)
103
+
104
+ with gr.Column():
105
+ pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
106
+ repo_id = gr.Dropdown(label="LLM", choices=["google/flan-ul2", "OpenAssistant/oasst-sft-1-pythia-12b", "bigscience/bloomz", "TheBloke/Llama-2-7b-Chat-GGUF"], value="google/flan-ul2")
107
+ with gr.Row():
108
+ langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
109
+ load_pdf = gr.Button("Load pdf to langchain")
110
+
111
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
112
+ question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
113
+ submit_btn = gr.Button("Send message")
114
+ #load_pdf.click(loading_pdf, None, langchain_status, queue=False)
115
+ repo_id.change(pdf_changes, inputs=[pdf_doc, repo_id], outputs=[langchain_status], queue=False)
116
+ load_pdf.click(pdf_changes, inputs=[pdf_doc, repo_id], outputs=[langchain_status], queue=False)
117
+ question.submit(add_text, [chatbot, question], [chatbot, question]).then(
118
+ bot, chatbot, chatbot
119
+ )
120
+ submit_btn.click(add_text, [chatbot, question], [chatbot, question]).then(
121
+ bot, chatbot, chatbot
122
+ )
123
 
124
  # Start the demo
125
  demo.show(True)