Ramon commited on
Commit
560b508
·
1 Parent(s): 7327b7d
Files changed (2) hide show
  1. app.py +45 -25
  2. requirements.txt +2 -2
app.py CHANGED
@@ -1,32 +1,52 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
 
4
- model = pipeline("text-generation", model="umarbutler/open-australian-legal-llm")
5
 
6
- def chat_fn(message, history):
7
- prompt = "You are a helpful, friendly and very senior lawyer who is an expert in criminal law advocacy and procedure. You advise clients on how to deal with police, police powers and what to do if arrested. You also represent in court and know everything about evidence and procedure. Here's your client's message: " + message
8
 
9
- # Generate text using the model
10
- response = model(prompt, max_length=500, num_return_sequences=1)
11
 
12
- # Extract the generated text from the response
13
- reply = response[0]['generated_text']
14
 
15
- # Update history with the new message format
16
- history.append({"role": "user", "content": message})
17
- history.append({"role": "assistant", "content": reply})
18
- return history
19
 
20
- with gr.Blocks() as dennis_denuto:
21
- chatbot = gr.Chatbot(
22
- placeholder="<strong>It's the vibe.</strong><br>Ask anything about criminal law and procedure in Australia.",
23
- type="messages"
24
- )
25
- gr.ChatInterface(
26
- fn=chat_fn,
27
- type="messages",
28
- chatbot=chatbot,
29
- save_history=True
30
- )
31
 
32
- dennis_denuto.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import gradio as gr
2
+ # from transformers import pipeline
3
 
4
+ # model = pipeline("text-generation", model="umarbutler/open-australian-legal-llm")
5
 
6
+ # def chat_fn(message, history):
7
+ # prompt = "You are a helpful, friendly and very senior lawyer who is an expert in criminal law advocacy and procedure. You advise clients on how to deal with police, police powers and what to do if arrested. You also represent in court and know everything about evidence and procedure. Here's your client's message: " + message
8
 
9
+ # # Generate text using the model
10
+ # response = model(prompt, max_length=500, num_return_sequences=1)
11
 
12
+ # # Extract the generated text from the response
13
+ # reply = response[0]['generated_text']
14
 
15
+ # # Update history with the new message format
16
+ # history.append({"role": "user", "content": message})
17
+ # history.append({"role": "assistant", "content": reply})
18
+ # return history
19
 
20
+ # with gr.Blocks() as dennis_denuto:
21
+ # chatbot = gr.Chatbot(
22
+ # placeholder="<strong>It's the vibe.</strong><br>Ask anything about criminal law and procedure in Australia.",
23
+ # type="messages"
24
+ # )
25
+ # gr.ChatInterface(
26
+ # fn=chat_fn,
27
+ # type="messages",
28
+ # chatbot=chatbot,
29
+ # save_history=True
30
+ # )
31
 
32
+ # dennis_denuto.launch()
33
+
34
+ import gradio as gr
35
+ from transformers import pipeline
36
+
37
+ model = pipeline("text-generation", model="umarbutler/open-australian-legal-llm")
38
+
39
+ def chatbot(input_text):
40
+ prompt = "You are a helpful, friendly and very senior lawyer who is an expert in criminal law advocacy and procedure. You advise clients on how to deal with police, police powers and what to do if arrested. You also represent in court and know everything about evidence and procedure. Here's your client's message: " + input_text
41
+ response = model(prompt, max_length=100, num_return_sequences=1)
42
+ return response[0]['generated_text']
43
+
44
+ iface = gr.Interface(
45
+ fn=chatbot,
46
+ inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
47
+ outputs="text",
48
+ title="Dennis Denuto LLM",
49
+ description="Ask anything about criminal law and procedure in Australia. It's the vibe."
50
+ )
51
+
52
+ iface.launch()
requirements.txt CHANGED
@@ -1,4 +1,4 @@
 
1
  gradio
2
- huggingface_hub
3
  transformers
4
- torch
 
1
+ huggingface_hub==0.22.2
2
  gradio
 
3
  transformers
4
+ torch # or tensorflow, depending on your model