Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,10 @@ import fitz # PyMuPDF
|
|
13 |
|
14 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
|
|
18 |
|
19 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
20 |
|
@@ -179,20 +181,8 @@ def extract_text_from_pdf(pdf_file):
|
|
179 |
return text
|
180 |
|
181 |
def ask_about_pdf(pdf_text, question):
|
182 |
-
|
183 |
-
|
184 |
-
for message in client.chat_completion(
|
185 |
-
[{"role": "system", "content": "You are a legal expert answering questions based on the PDF content provided."},
|
186 |
-
{"role": "user", "content": prompt}],
|
187 |
-
max_tokens=512,
|
188 |
-
stream=True,
|
189 |
-
temperature=0.6,
|
190 |
-
top_p=0.95,
|
191 |
-
):
|
192 |
-
token = message.choices[0].delta.content
|
193 |
-
if token is not None:
|
194 |
-
response += token
|
195 |
-
return response
|
196 |
|
197 |
def update_pdf_gallery_and_extract_text(pdf_files):
|
198 |
if len(pdf_files) > 0:
|
@@ -202,20 +192,8 @@ def update_pdf_gallery_and_extract_text(pdf_files):
|
|
202 |
return pdf_files, pdf_text
|
203 |
|
204 |
def get_top_10_cases():
|
205 |
-
|
206 |
-
|
207 |
-
for message in client.chat_completion(
|
208 |
-
[{"role": "system", "content": "You are a legal expert providing information about top legal cases."},
|
209 |
-
{"role": "user", "content": prompt}],
|
210 |
-
max_tokens=512,
|
211 |
-
stream=True,
|
212 |
-
temperature=0.6,
|
213 |
-
top_p=0.95,
|
214 |
-
):
|
215 |
-
token = message.choices[0].delta.content
|
216 |
-
if token is not None:
|
217 |
-
response += token
|
218 |
-
return response
|
219 |
|
220 |
def add_message(history, message):
|
221 |
for x in message["files"]:
|
@@ -256,20 +234,8 @@ def save_conversation(history1, history2, shared_history):
|
|
256 |
return history1, history2, shared_history
|
257 |
|
258 |
def ask_about_case_outcome(shared_history, question):
|
259 |
-
|
260 |
-
|
261 |
-
for message in client.chat_completion(
|
262 |
-
[{"role": "system", "content": "You are a legal expert answering questions based on the case outcome provided."},
|
263 |
-
{"role": "user", "content": prompt}],
|
264 |
-
max_tokens=512,
|
265 |
-
stream=True,
|
266 |
-
temperature=0.6,
|
267 |
-
top_p=0.95,
|
268 |
-
):
|
269 |
-
token = message.choices[0].delta.content
|
270 |
-
if token is not None:
|
271 |
-
response += token
|
272 |
-
return response
|
273 |
|
274 |
with gr.Blocks(css=custom_css) as demo:
|
275 |
history1 = gr.State([])
|
|
|
13 |
|
14 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
15 |
|
16 |
+
# Different pipelines for different tasks
|
17 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
18 |
+
summarization_pipeline = pipeline("summarization", model="facebook/bart-large-cnn")
|
19 |
+
mask_filling_pipeline = pipeline("fill-mask", model="nlpaueb/legal-bert-base-uncased")
|
20 |
|
21 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
22 |
|
|
|
181 |
return text
|
182 |
|
183 |
def ask_about_pdf(pdf_text, question):
|
184 |
+
result = qa_pipeline(question=question, context=pdf_text)
|
185 |
+
return result['answer']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
def update_pdf_gallery_and_extract_text(pdf_files):
|
188 |
if len(pdf_files) > 0:
|
|
|
192 |
return pdf_files, pdf_text
|
193 |
|
194 |
def get_top_10_cases():
|
195 |
+
result = summarization_pipeline("Top 10 current legal cases in the country", max_length=150, min_length=50, do_sample=False)
|
196 |
+
return result[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
def add_message(history, message):
|
199 |
for x in message["files"]:
|
|
|
234 |
return history1, history2, shared_history
|
235 |
|
236 |
def ask_about_case_outcome(shared_history, question):
|
237 |
+
result = qa_pipeline(question=question, context=shared_history)
|
238 |
+
return result['answer']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
with gr.Blocks(css=custom_css) as demo:
|
241 |
history1 = gr.State([])
|