PKaushik commited on
Commit
3e6934a
·
verified ·
1 Parent(s): 2db95d5

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -61
app.py DELETED
@@ -1,61 +0,0 @@
1
- import gradio as gr
2
- import torch
3
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
4
- from peft import PeftModel
5
-
6
- # Load the model and tokenizer
7
- model = AutoModelForCausalLM.from_pretrained(
8
- "Equall/Saul-7B-Base",
9
- quantization_config=BitsAndBytesConfig(load_in_8bit=True),
10
- device_map="auto",
11
- )
12
-
13
- tokenizer = AutoTokenizer.from_pretrained("Equall/Saul-7B-Base")
14
- tokenizer.pad_token = tokenizer.eos_token
15
-
16
- model = PeftModel.from_pretrained(
17
- model,
18
- "auslawbench/Cite-SaulLM-7B",
19
- device_map="auto",
20
- torch_dtype=torch.bfloat16,
21
- )
22
- model.eval()
23
-
24
- # Define the prediction function
25
- def predict_case_citation(instruction, input_text):
26
- fine_tuned_prompt = """
27
- ### Instruction:
28
- {}
29
-
30
- ### Input:
31
- {}
32
-
33
- ### Response:
34
- """
35
- model_input = fine_tuned_prompt.format(instruction, input_text)
36
- inputs = tokenizer(model_input, return_tensors="pt").to("cuda")
37
- outputs = model.generate(**inputs, max_new_tokens=256, temperature=1.0)
38
- output = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
- response = output.split("### Response:")[1].strip().split('>')[0] + '>'
40
- return response
41
-
42
- # Create the Gradio interface
43
- iface = gr.Interface(
44
- fn=predict_case_citation,
45
- inputs=[
46
- gr.Textbox(label="Instruction", value="Predict the name of the case that needs to be cited in the text and explain why it should be cited."),
47
- gr.Textbox(label="Input Text", lines=5)
48
- ],
49
- outputs=gr.Textbox(label="Predicted Case Citation"),
50
- title="Case Citation Predictor",
51
- description="This app predicts the name of the case that should be cited in the given legal text.",
52
- examples=[
53
- [
54
- "Predict the name of the case that needs to be cited in the text and explain why it should be cited.",
55
- "Many of ZAR's grounds of appeal related to fact finding. Drawing on principles set down in several other courts and tribunals, the Appeal Panel summarised the circumstances in which leave may be granted for a person to appeal from findings of fact: <CASENAME> at [84]."
56
- ]
57
- ]
58
- )
59
-
60
- # Launch the app
61
- iface.launch()