asthaa30 commited on
Commit
8a80b79
·
verified ·
1 Parent(s): 33b6f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -27
app.py CHANGED
@@ -7,56 +7,64 @@ 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
  def respond(
13
  message,
14
  history: list[tuple[str, str]],
15
- system_message: str,
16
- max_tokens: int,
17
- temperature: float,
18
- top_p: float,
19
  ):
20
  messages = [{"role": "system", "content": system_message}]
21
 
22
- for user_message, assistant_message in history:
23
- if user_message:
24
- messages.append({"role": "user", "content": user_message})
25
- if assistant_message:
26
- messages.append({"role": "assistant", "content": assistant_message})
27
 
28
  messages.append({"role": "user", "content": message})
29
 
30
  response = ""
31
-
32
- # Assuming correct method for Groq client
33
- for message in client.complete_chat(
34
- ChatCompletionToolParam(
35
- messages=messages,
36
- max_tokens=max_tokens,
37
- temperature=temperature,
38
- top_p=top_p,
39
- stream=True
40
- )
41
  ):
42
- token = message.choices[0].delta.get("content", "")
 
43
  response += token
44
  yield response
45
 
 
 
 
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
- gr.Textbox(
50
- 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.",
51
- label="System message"
52
- ),
53
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
56
  ],
57
  title="Maritime Legal Compliance",
58
- description="This chatbot uses the fine-tuned Llama 3.1 which has the capabilities of responding and helping in legal advices regarding maritime.",
59
  )
60
 
 
61
  if __name__ == "__main__":
62
  demo.launch()
 
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
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
13
+
14
 
15
  def respond(
16
  message,
17
  history: list[tuple[str, str]],
18
+ system_message,
19
+ max_tokens,
20
+ temperature,
21
+ top_p,
22
  ):
23
  messages = [{"role": "system", "content": system_message}]
24
 
25
+ for val in history:
26
+ if val[0]:
27
+ messages.append({"role": "user", "content": val[0]})
28
+ if val[1]:
29
+ messages.append({"role": "assistant", "content": val[1]})
30
 
31
  messages.append({"role": "user", "content": message})
32
 
33
  response = ""
34
+
35
+ for message in client.chat_completion(
36
+ messages,
37
+ max_tokens=max_tokens,
38
+ stream=True,
39
+ temperature=temperature,
40
+ top_p=top_p,
 
 
 
41
  ):
42
+ token = message.choices[0].delta.content
43
+
44
  response += token
45
  yield response
46
 
47
+ """
48
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
49
+ """
50
  demo = gr.ChatInterface(
51
  respond,
52
  additional_inputs=[
53
+ gr.Textbox(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.", label="System message"),
 
 
 
54
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
55
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
56
+ gr.Slider(
57
+ minimum=0.1,
58
+ maximum=1.0,
59
+ value=0.95,
60
+ step=0.05,
61
+ label="Top-p (nucleus sampling)",
62
+ ),
63
  ],
64
  title="Maritime Legal Compliance",
65
+ description="This chatbot uses the fine tune Llama 3.1 which has the capabilities of responding and helping in legal advices regarding maritime",
66
  )
67
 
68
+
69
  if __name__ == "__main__":
70
  demo.launch()