michaelmc1618 commited on
Commit
d716ab3
·
verified ·
1 Parent(s): 4f4bbd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -9,27 +9,25 @@ import gradio as gr
9
  from huggingface_hub import InferenceClient
10
  from transformers import pipeline
11
  from datasets import load_dataset
12
- import time
13
  import fitz # PyMuPDF
14
 
15
- dataset = load_dataset("ibunescu/qa_legal_dataset_train")
16
 
17
- return evaluation
18
 
19
  def score_argument_from_outcome(outcome, argument):
20
-
21
  if "Prosecutor" in outcome:
22
  prosecutor_score = outcome.count("Prosecutor") * 2
23
  if "won" in outcome and "Prosecutor" in outcome:
24
- }
25
- """
26
-
27
 
28
  def chat_between_bots(system_message1, system_message2, max_tokens, temperature, top_p, history1, history2, shared_history, message):
29
  response1, history1 = list(respond(message, history1, system_message1, max_tokens, temperature, top_p))[-1]
30
  response2, history2 = list(respond(message, history2, system_message2, max_tokens, temperature, top_p))[-1]
31
 
32
- return response1, response2, history1, history2, shared_history, outcome, prosecutor_score_color, defense_score_color
33
 
34
  def extract_text_from_pdf(pdf_file):
35
  text = ""
@@ -62,8 +60,8 @@ def update_pdf_gallery_and_extract_text(pdf_files):
62
  return pdf_files, pdf_text
63
 
64
  def add_message(history, message):
65
- for x in message["files"]:
66
- return history, gr.MultimodalTextbox(value=None, interactive=False)
67
 
68
  def bot(history):
69
  system_message = "You are a helpful assistant."
@@ -96,6 +94,13 @@ def reset_conversation():
96
  def save_conversation(history1, history2, shared_history):
97
  return history1, history2, shared_history
98
 
 
 
 
 
 
 
 
99
  with gr.Blocks(css=custom_css) as demo:
100
  history1 = gr.State([])
101
  history2 = gr.State([])
@@ -105,8 +110,18 @@ with gr.Blocks(css=custom_css) as demo:
105
 
106
  with gr.Tab("Argument Evaluation"):
107
  message = gr.Textbox(label="Case to Argue")
 
 
 
 
 
108
 
 
 
 
 
109
  shared_argument = gr.Textbox(label="Case Outcome", interactive=True)
 
110
  submit_btn = gr.Button("Argue")
111
  clear_btn = gr.Button("Clear and Reset")
112
  save_btn = gr.Button("Save Conversation")
@@ -123,10 +138,12 @@ with gr.Blocks(css=custom_css) as demo:
123
  pdf_answer = gr.Textbox(label="Answer", interactive=False, elem_classes=["scroll-box"])
124
  pdf_upload_btn = gr.Button("Update PDF Gallery")
125
  pdf_ask_btn = gr.Button("Ask")
126
-
127
  pdf_upload_btn.click(update_pdf_gallery_and_extract_text, inputs=[pdf_upload], outputs=[pdf_gallery, pdf_text])
128
  pdf_text.change(fn=lambda x: x, inputs=pdf_text, outputs=pdf_view)
129
  pdf_ask_btn.click(ask_about_pdf, inputs=[pdf_text, pdf_question], outputs=pdf_answer)
130
 
131
  with gr.Tab("Chatbot"):
132
- chatbot = gr.Chatbot(
 
 
 
9
  from huggingface_hub import InferenceClient
10
  from transformers import pipeline
11
  from datasets import load_dataset
 
12
  import fitz # PyMuPDF
13
 
14
+ client = InferenceClient()
15
 
16
+ dataset = load_dataset("ibunescu/qa_legal_dataset_train")
17
 
18
  def score_argument_from_outcome(outcome, argument):
19
+ prosecutor_score = 0
20
  if "Prosecutor" in outcome:
21
  prosecutor_score = outcome.count("Prosecutor") * 2
22
  if "won" in outcome and "Prosecutor" in outcome:
23
+ prosecutor_score += 10
24
+ return prosecutor_score
 
25
 
26
  def chat_between_bots(system_message1, system_message2, max_tokens, temperature, top_p, history1, history2, shared_history, message):
27
  response1, history1 = list(respond(message, history1, system_message1, max_tokens, temperature, top_p))[-1]
28
  response2, history2 = list(respond(message, history2, system_message2, max_tokens, temperature, top_p))[-1]
29
 
30
+ return response1, response2, history1, history2, shared_history
31
 
32
  def extract_text_from_pdf(pdf_file):
33
  text = ""
 
60
  return pdf_files, pdf_text
61
 
62
  def add_message(history, message):
63
+ history.append(message)
64
+ return history, gr.Textbox(value=None, interactive=False)
65
 
66
  def bot(history):
67
  system_message = "You are a helpful assistant."
 
94
  def save_conversation(history1, history2, shared_history):
95
  return history1, history2, shared_history
96
 
97
+ custom_css = """
98
+ .scroll-box {
99
+ max-height: 400px;
100
+ overflow-y: auto;
101
+ }
102
+ """
103
+
104
  with gr.Blocks(css=custom_css) as demo:
105
  history1 = gr.State([])
106
  history2 = gr.State([])
 
110
 
111
  with gr.Tab("Argument Evaluation"):
112
  message = gr.Textbox(label="Case to Argue")
113
+ system_message1 = "System message for bot 1"
114
+ system_message2 = "System message for bot 2"
115
+ max_tokens = 150
116
+ temperature = 0.6
117
+ top_p = 0.95
118
 
119
+ prosecutor_response = gr.Textbox(label="Prosecutor Response", interactive=False)
120
+ defense_response = gr.Textbox(label="Defense Response", interactive=False)
121
+ prosecutor_score_color = gr.Textbox(label="Prosecutor Score Color", interactive=False)
122
+ defense_score_color = gr.Textbox(label="Defense Score Color", interactive=False)
123
  shared_argument = gr.Textbox(label="Case Outcome", interactive=True)
124
+
125
  submit_btn = gr.Button("Argue")
126
  clear_btn = gr.Button("Clear and Reset")
127
  save_btn = gr.Button("Save Conversation")
 
138
  pdf_answer = gr.Textbox(label="Answer", interactive=False, elem_classes=["scroll-box"])
139
  pdf_upload_btn = gr.Button("Update PDF Gallery")
140
  pdf_ask_btn = gr.Button("Ask")
141
+
142
  pdf_upload_btn.click(update_pdf_gallery_and_extract_text, inputs=[pdf_upload], outputs=[pdf_gallery, pdf_text])
143
  pdf_text.change(fn=lambda x: x, inputs=pdf_text, outputs=pdf_view)
144
  pdf_ask_btn.click(ask_about_pdf, inputs=[pdf_text, pdf_question], outputs=pdf_answer)
145
 
146
  with gr.Tab("Chatbot"):
147
+ chatbot = gr.Chatbot()
148
+
149
+ demo.launch()