Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
|
|
8 |
from huggingface_hub import InferenceClient
|
9 |
from transformers import pipeline
|
10 |
from datasets import load_dataset
|
|
|
11 |
|
12 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
13 |
|
@@ -182,7 +183,23 @@ def chat_between_bots(system_message1, system_message2, max_tokens, temperature,
|
|
182 |
def update_pdf_gallery(pdf_files):
|
183 |
return pdf_files
|
184 |
|
185 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
with gr.Blocks(css=custom_css) as demo:
|
187 |
history1 = gr.State([])
|
188 |
history2 = gr.State([])
|
@@ -208,7 +225,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
208 |
defense_score_color = gr.HTML()
|
209 |
|
210 |
shared_argument = gr.Textbox(label="Case Outcome", interactive=True)
|
211 |
-
pdf_upload = gr.File(label="Upload Case Files (PDF)", file_types=[".pdf"]
|
212 |
pdf_gallery = gr.Gallery(label="PDF Gallery")
|
213 |
|
214 |
submit_btn = gr.Button("Argue")
|
@@ -217,5 +234,20 @@ with gr.Blocks(css=custom_css) as demo:
|
|
217 |
submit_btn.click(chat_between_bots, inputs=[system_message1, system_message2, max_tokens, temperature, top_p, history1, history2, shared_history, message], outputs=[prosecutor_response, defense_response, history1, history2, shared_history, shared_argument, prosecutor_score_color, defense_score_color])
|
218 |
pdf_upload_btn.click(update_pdf_gallery, inputs=[pdf_upload], outputs=[pdf_gallery, pdf_files])
|
219 |
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from huggingface_hub import InferenceClient
|
9 |
from transformers import pipeline
|
10 |
from datasets import load_dataset
|
11 |
+
import time
|
12 |
|
13 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
14 |
|
|
|
183 |
def update_pdf_gallery(pdf_files):
|
184 |
return pdf_files
|
185 |
|
186 |
+
# Function to add message to the chatbot
|
187 |
+
def add_message(history, message):
|
188 |
+
for x in message["files"]:
|
189 |
+
history.append(((x,), None))
|
190 |
+
if message["text"] is not None:
|
191 |
+
history.append((message["text"], None))
|
192 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
193 |
+
|
194 |
+
# Bot function to simulate response
|
195 |
+
def bot(history):
|
196 |
+
response = "**That's cool!**"
|
197 |
+
history[-1][1] = ""
|
198 |
+
for character in response:
|
199 |
+
history[-1][1] += character
|
200 |
+
time.sleep(0.05)
|
201 |
+
yield history
|
202 |
+
|
203 |
with gr.Blocks(css=custom_css) as demo:
|
204 |
history1 = gr.State([])
|
205 |
history2 = gr.State([])
|
|
|
225 |
defense_score_color = gr.HTML()
|
226 |
|
227 |
shared_argument = gr.Textbox(label="Case Outcome", interactive=True)
|
228 |
+
pdf_upload = gr.File(label="Upload Case Files (PDF)", file_types=[".pdf"])
|
229 |
pdf_gallery = gr.Gallery(label="PDF Gallery")
|
230 |
|
231 |
submit_btn = gr.Button("Argue")
|
|
|
234 |
submit_btn.click(chat_between_bots, inputs=[system_message1, system_message2, max_tokens, temperature, top_p, history1, history2, shared_history, message], outputs=[prosecutor_response, defense_response, history1, history2, shared_history, shared_argument, prosecutor_score_color, defense_score_color])
|
235 |
pdf_upload_btn.click(update_pdf_gallery, inputs=[pdf_upload], outputs=[pdf_gallery, pdf_files])
|
236 |
|
237 |
+
# Chatbot section
|
238 |
+
chatbot = gr.Chatbot(
|
239 |
+
[],
|
240 |
+
elem_id="chatbot",
|
241 |
+
bubble_full_width=False
|
242 |
+
)
|
243 |
+
|
244 |
+
chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)
|
245 |
+
|
246 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
247 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
248 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
249 |
+
|
250 |
+
chatbot.like(print_like_dislike, None, None)
|
251 |
+
|
252 |
+
demo.queue()
|
253 |
+
demo.launch()
|