Spaces:
Runtime error

File size: 1,479 Bytes
1c48ecf
534f2c4
e052f94
a453298
 
 
 
 
e052f94
a453298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e052f94
534f2c4
e052f94
a453298
 
 
 
 
 
e052f94
 
534f2c4
e052f94
 
a453298
534f2c4
a453298
534f2c4
a453298
 
 
 
 
 
 
534f2c4
 
a453298
 
 
7cf3a2c
a453298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import gradio
from groq import Groq

client = Groq(
    api_key="YOUR_API_KEY",
)

def initialize_messages():
    return [
        {
            "role": "system",
            "content": (
                "You are a skilled criminal lawyer with a "
                "successful track record in numerous cases. "
                "Your role is to assist people by providing "
                "guidance on Indian laws and offering answers "
                "in a professional legal manner."
            ),
        }
    ]


messages_prmt = initialize_messages()


def customLLMBot(user_input, history):
    global messages_prmt

    messages_prmt.append(
        {
            "role": "user",
            "content": user_input,
        }
    )

    response = client.chat.completions.create(
        messages=messages_prmt,
        model="llama-3.3-70b-versatile",
    )

    print(response)

    LLM_reply = response.choices[0].message.content

    messages_prmt.append(
        {
            "role": "assistant",
            "content": LLM_reply,
        }
    )

    return LLM_reply


iface = gradio.ChatInterface(
    customLLMBot,
    chatbot=gradio.Chatbot(height=300),
    textbox=gradio.Textbox(
        placeholder="Ask me a question related to law"
    ),
    title="Lawyer ChatBot",
    description="Chat bot for law assistance",
    theme="soft",
    examples=[
        "hi",
        "What is IPC sections",
        "how to get a bail",
    ],
)

iface.launch()