Added spaces code
Browse files- .ipynb_checkpoints/README-checkpoint.md +13 -0
- .ipynb_checkpoints/app-checkpoint.py +58 -0
- .ipynb_checkpoints/requirements-checkpoint.txt +2 -0
- README.md +2 -1
- app.py +2 -7
- requirements.txt +2 -1
.ipynb_checkpoints/README-checkpoint.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Law LM
|
3 |
+
emoji: 💬
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
license: llama3
|
10 |
+
---
|
11 |
+
|
12 |
+
# About
|
13 |
+
Law Language Model is an RAG (**Retrieval Augmented Generation**) based LLM (**Large Language Model**) application that is used to solve one of the complex problem that is understanding **LAW** of India. As of now there is no availability for a common man in India to learn or know about Law. So this project's aim to provide a clarification of India Law with the implementation of RAG based LLM.
|
.ipynb_checkpoints/app-checkpoint.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import spaces
|
4 |
+
|
5 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
+
|
7 |
+
@spaces.GPU
|
8 |
+
def respond(
|
9 |
+
message,
|
10 |
+
history: list[tuple[str, str]],
|
11 |
+
system_message,
|
12 |
+
max_tokens,
|
13 |
+
temperature,
|
14 |
+
top_p,
|
15 |
+
):
|
16 |
+
messages = [{"role": "system", "content": system_message}]
|
17 |
+
|
18 |
+
for val in history:
|
19 |
+
if val[0]:
|
20 |
+
messages.append({"role": "user", "content": val[0]})
|
21 |
+
if val[1]:
|
22 |
+
messages.append({"role": "assistant", "content": val[1]})
|
23 |
+
|
24 |
+
messages.append({"role": "user", "content": message})
|
25 |
+
|
26 |
+
response = ""
|
27 |
+
|
28 |
+
for message in client.chat_completion(
|
29 |
+
messages,
|
30 |
+
max_tokens=max_tokens,
|
31 |
+
stream=True,
|
32 |
+
temperature=temperature,
|
33 |
+
top_p=top_p,
|
34 |
+
):
|
35 |
+
token = message.choices[0].delta.content
|
36 |
+
|
37 |
+
response += token
|
38 |
+
yield response
|
39 |
+
|
40 |
+
demo = gr.ChatInterface(
|
41 |
+
respond,
|
42 |
+
additional_inputs=[
|
43 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
44 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
45 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
46 |
+
gr.Slider(
|
47 |
+
minimum=0.1,
|
48 |
+
maximum=1.0,
|
49 |
+
value=0.95,
|
50 |
+
step=0.05,
|
51 |
+
label="Top-p (nucleus sampling)",
|
52 |
+
),
|
53 |
+
],
|
54 |
+
)
|
55 |
+
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
demo.launch()
|
.ipynb_checkpoints/requirements-checkpoint.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
huggingface_hub==0.22.2
|
2 |
+
spaces
|
README.md
CHANGED
@@ -9,4 +9,5 @@ pinned: false
|
|
9 |
license: llama3
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
9 |
license: llama3
|
10 |
---
|
11 |
|
12 |
+
# About
|
13 |
+
Law Language Model is an RAG (**Retrieval Augmented Generation**) based LLM (**Large Language Model**) application that is used to solve one of the complex problem that is understanding **LAW** of India. As of now there is no availability for a common man in India to learn or know about Law. So this project's aim to provide a clarification of India Law with the implementation of RAG based LLM.
|
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -39,9 +37,6 @@ def respond(
|
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
"""
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import spaces
|
4 |
|
|
|
|
|
|
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
7 |
+
@spaces.GPU
|
8 |
def respond(
|
9 |
message,
|
10 |
history: list[tuple[str, str]],
|
|
|
37 |
response += token
|
38 |
yield response
|
39 |
|
|
|
|
|
|
|
40 |
demo = gr.ChatInterface(
|
41 |
respond,
|
42 |
additional_inputs=[
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
huggingface_hub==0.22.2
|
|
|
|
1 |
+
huggingface_hub==0.22.2
|
2 |
+
spaces
|