gauravchand11 commited on
Commit
0166259
Β·
verified Β·
1 Parent(s): 7aed019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -20,7 +20,7 @@ HF_TOKEN = os.getenv('HF_TOKEN')
20
  AZURE_TRANSLATION_KEY = os.getenv('AZURE_TRANSLATION_KEY')
21
 
22
  class Translator:
23
- def _init_(self):
24
  self.key = AZURE_TRANSLATION_KEY
25
  self.region = 'centralindia'
26
  self.endpoint = "https://api.cognitive.microsofttranslator.com"
@@ -99,7 +99,7 @@ class TextExtractor:
99
  return "Unsupported input type"
100
 
101
  class LegalEaseAssistant:
102
- def _init_(self):
103
  if not HF_TOKEN:
104
  raise ValueError("Hugging Face token not found. Please set the HF_TOKEN environment variable.")
105
 
@@ -135,7 +135,7 @@ class LegalEaseAssistant:
135
 
136
  prompt = task_prompts.get(task_type, f"Analyze the following text and provide points:\n\n{text}\n\nAnalysis:")
137
 
138
- inputs = self.tokenizer(prompt, return_tensors="pt")
139
  outputs = self.model.generate(
140
  **inputs,
141
  max_new_tokens=300,
@@ -207,7 +207,7 @@ def create_interface():
207
  with gr.Row():
208
  with gr.Column(scale=1):
209
  simplify_input = gr.File(
210
- file_types=['txt', 'pdf', 'image'],
211
  label="πŸ“Ž Upload Document"
212
  )
213
  gr.HTML("<div style='height: 10px'></div>")
@@ -250,7 +250,7 @@ def create_interface():
250
  with gr.Row():
251
  with gr.Column(scale=1):
252
  summary_input = gr.File(
253
- file_types=['txt', 'pdf', 'image'],
254
  label="πŸ“Ž Upload Document"
255
  )
256
  gr.HTML("<div style='height: 10px'></div>")
@@ -294,7 +294,7 @@ def create_interface():
294
  with gr.Row():
295
  with gr.Column(scale=1):
296
  terms_input = gr.File(
297
- file_types=['txt', 'pdf', 'image'],
298
  label="πŸ“Ž Upload Document"
299
  )
300
  gr.HTML("<div style='height: 10px'></div>")
@@ -338,7 +338,7 @@ def create_interface():
338
  with gr.Row():
339
  with gr.Column(scale=1):
340
  contract1_input = gr.File(
341
- file_types=['txt', 'pdf', 'image'],
342
  label="πŸ“Ž Upload First Contract"
343
  )
344
  gr.HTML("<div style='height: 10px'></div>")
@@ -350,7 +350,7 @@ def create_interface():
350
 
351
  with gr.Column(scale=1):
352
  contract2_input = gr.File(
353
- file_types=['txt', 'pdf', 'image'],
354
  label="πŸ“Ž Upload Second Contract"
355
  )
356
  gr.HTML("<div style='height: 10px'></div>")
@@ -378,22 +378,25 @@ def create_interface():
378
  if not contract1 or not contract2:
379
  return "Please provide both contracts for comparison."
380
 
 
 
 
 
 
 
381
  def compare_contracts(contract1, contract2):
382
  prompt = f"""Compare these two contracts and identify key differences and similarities:
383
-
384
  Contract 1:
385
  {contract1}
386
-
387
  Contract 2:
388
  {contract2}
389
-
390
  Please analyze and list:
391
  1. Key similarities
392
  2. Important differences
393
  3. Unique terms in each contract
394
  4. Potential implications of the differences"""
395
 
396
- inputs = assistant.tokenizer(prompt, return_tensors="pt")
397
  outputs = assistant.model.generate(
398
  **inputs,
399
  max_new_tokens=400,
@@ -427,7 +430,7 @@ Please analyze and list:
427
  with gr.Row():
428
  with gr.Column(scale=1):
429
  risk_input = gr.File(
430
- file_types=['txt', 'pdf', 'image'],
431
  label="πŸ“Ž Upload Document"
432
  )
433
  gr.HTML("<div style='height: 10px'></div>")
 
20
  AZURE_TRANSLATION_KEY = os.getenv('AZURE_TRANSLATION_KEY')
21
 
22
  class Translator:
23
+ def __init__(self): # Fixed method name from _init_ to __init__
24
  self.key = AZURE_TRANSLATION_KEY
25
  self.region = 'centralindia'
26
  self.endpoint = "https://api.cognitive.microsofttranslator.com"
 
99
  return "Unsupported input type"
100
 
101
  class LegalEaseAssistant:
102
+ def __init__(self): # Fixed method name from _init_ to __init__
103
  if not HF_TOKEN:
104
  raise ValueError("Hugging Face token not found. Please set the HF_TOKEN environment variable.")
105
 
 
135
 
136
  prompt = task_prompts.get(task_type, f"Analyze the following text and provide points:\n\n{text}\n\nAnalysis:")
137
 
138
+ inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device) # Add to(device) to ensure tensor is on the right device
139
  outputs = self.model.generate(
140
  **inputs,
141
  max_new_tokens=300,
 
207
  with gr.Row():
208
  with gr.Column(scale=1):
209
  simplify_input = gr.File(
210
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
211
  label="πŸ“Ž Upload Document"
212
  )
213
  gr.HTML("<div style='height: 10px'></div>")
 
250
  with gr.Row():
251
  with gr.Column(scale=1):
252
  summary_input = gr.File(
253
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
254
  label="πŸ“Ž Upload Document"
255
  )
256
  gr.HTML("<div style='height: 10px'></div>")
 
294
  with gr.Row():
295
  with gr.Column(scale=1):
296
  terms_input = gr.File(
297
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
298
  label="πŸ“Ž Upload Document"
299
  )
300
  gr.HTML("<div style='height: 10px'></div>")
 
338
  with gr.Row():
339
  with gr.Column(scale=1):
340
  contract1_input = gr.File(
341
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
342
  label="πŸ“Ž Upload First Contract"
343
  )
344
  gr.HTML("<div style='height: 10px'></div>")
 
350
 
351
  with gr.Column(scale=1):
352
  contract2_input = gr.File(
353
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
354
  label="πŸ“Ž Upload Second Contract"
355
  )
356
  gr.HTML("<div style='height: 10px'></div>")
 
378
  if not contract1 or not contract2:
379
  return "Please provide both contracts for comparison."
380
 
381
+ # Extract text if needed
382
+ if not isinstance(contract1, str):
383
+ contract1 = assistant.text_extractor.extract_text_from_input(contract1)
384
+ if not isinstance(contract2, str):
385
+ contract2 = assistant.text_extractor.extract_text_from_input(contract2)
386
+
387
  def compare_contracts(contract1, contract2):
388
  prompt = f"""Compare these two contracts and identify key differences and similarities:
 
389
  Contract 1:
390
  {contract1}
 
391
  Contract 2:
392
  {contract2}
 
393
  Please analyze and list:
394
  1. Key similarities
395
  2. Important differences
396
  3. Unique terms in each contract
397
  4. Potential implications of the differences"""
398
 
399
+ inputs = assistant.tokenizer(prompt, return_tensors="pt").to(assistant.model.device) # Add to(device) to ensure tensor is on the right device
400
  outputs = assistant.model.generate(
401
  **inputs,
402
  max_new_tokens=400,
 
430
  with gr.Row():
431
  with gr.Column(scale=1):
432
  risk_input = gr.File(
433
+ file_types=['txt', 'pdf', 'jpg', 'jpeg', 'png'], # Added image file types explicitly
434
  label="πŸ“Ž Upload Document"
435
  )
436
  gr.HTML("<div style='height: 10px'></div>")