Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,74 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import os
|
|
|
4 |
from groq import Groq
|
5 |
from groq.types.chat.chat_completion_tool_param import ChatCompletionToolParam
|
6 |
|
7 |
# Use the fine-tuned maritime legal model
|
8 |
MODEL = "nomiChroma3.1"
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
-
from huggingface_hub import InferenceClient
|
13 |
|
14 |
"""
|
15 |
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
|
16 |
"""
|
17 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
18 |
-
|
19 |
|
|
|
20 |
def respond(
|
21 |
message,
|
22 |
history: list[tuple[str, str]],
|
@@ -72,4 +124,5 @@ demo = gr.ChatInterface(
|
|
72 |
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
-
demo.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import os
|
4 |
+
from huggingface_hub import InferenceClient
|
5 |
from groq import Groq
|
6 |
from groq.types.chat.chat_completion_tool_param import ChatCompletionToolParam
|
7 |
|
8 |
# Use the fine-tuned maritime legal model
|
9 |
MODEL = "nomiChroma3.1"
|
10 |
+
client = Groq(api_key=os.environ["GROQ_API_KEY"])
|
11 |
+
|
12 |
+
|
13 |
+
def respond(
|
14 |
+
message,
|
15 |
+
history: list[tuple[str, str]],
|
16 |
+
system_message: str,
|
17 |
+
max_tokens: int,
|
18 |
+
temperature: float,
|
19 |
+
top_p: float,
|
20 |
+
):
|
21 |
+
messages = [{"role": "system", "content": system_message}]
|
22 |
+
|
23 |
+
for user_message, assistant_message in history:
|
24 |
+
if user_message:
|
25 |
+
messages.append({"role": "user", "content": user_message})
|
26 |
+
if assistant_message:
|
27 |
+
messages.append({"role": "assistant", "content": assistant_message})
|
28 |
+
|
29 |
+
messages.append({"role": "user", "content": message})
|
30 |
+
|
31 |
+
response = ""
|
32 |
+
for message in client.chat_completion(
|
33 |
+
ChatCompletionToolParam(
|
34 |
+
messages=messages,
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
temperature=temperature,
|
37 |
+
top_p=top_p,
|
38 |
+
stream=True
|
39 |
+
)
|
40 |
+
):
|
41 |
+
token = message.choices[0].delta.get("content", "")
|
42 |
+
response += token
|
43 |
+
yield response
|
44 |
+
|
45 |
+
demo = gr.ChatInterface(
|
46 |
+
respond,
|
47 |
+
additional_inputs=[
|
48 |
+
gr.Textbox(
|
49 |
+
value="You are a maritime legal assistant with expertise strictly in Indian maritime law. Provide detailed legal advice and information based on Indian maritime legal principles and regulations.",
|
50 |
+
label="System message"
|
51 |
+
),
|
52 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
53 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
54 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
55 |
+
],
|
56 |
+
title="Maritime Legal Compliance",
|
57 |
+
description="This chatbot uses the fine-tuned Llama 3.1 which has the capabilities of responding and helping in legal advices regarding maritime.",
|
58 |
+
)
|
59 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
demo.launch()
|
62 |
+
|
63 |
|
64 |
|
|
|
65 |
|
66 |
"""
|
67 |
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
|
68 |
"""
|
69 |
+
##client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
70 |
|
71 |
+
"""
|
72 |
def respond(
|
73 |
message,
|
74 |
history: list[tuple[str, str]],
|
|
|
124 |
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
+
demo.launch()
|
128 |
+
"""
|