Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,72 @@
|
|
| 1 |
import os
|
| 2 |
import gradio
|
| 3 |
from groq import Groq
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def initialize_messages():
|
| 6 |
-
return [
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def customLLMBot(user_input, history):
|
| 13 |
global messages_prmt
|
| 14 |
|
| 15 |
-
messages_prmt.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
response = client.chat.completions.create(
|
| 18 |
messages=messages_prmt,
|
| 19 |
model="llama-3.3-70b-versatile",
|
| 20 |
)
|
|
|
|
| 21 |
print(response)
|
|
|
|
| 22 |
LLM_reply = response.choices[0].message.content
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
return LLM_reply
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio
|
| 3 |
from groq import Groq
|
| 4 |
+
|
| 5 |
+
client = Groq(
|
| 6 |
+
api_key="YOUR_API_KEY",
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
def initialize_messages():
|
| 10 |
+
return [
|
| 11 |
+
{
|
| 12 |
+
"role": "system",
|
| 13 |
+
"content": (
|
| 14 |
+
"You are a skilled criminal lawyer with a "
|
| 15 |
+
"successful track record in numerous cases. "
|
| 16 |
+
"Your role is to assist people by providing "
|
| 17 |
+
"guidance on Indian laws and offering answers "
|
| 18 |
+
"in a professional legal manner."
|
| 19 |
+
),
|
| 20 |
+
}
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
messages_prmt = initialize_messages()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
def customLLMBot(user_input, history):
|
| 28 |
global messages_prmt
|
| 29 |
|
| 30 |
+
messages_prmt.append(
|
| 31 |
+
{
|
| 32 |
+
"role": "user",
|
| 33 |
+
"content": user_input,
|
| 34 |
+
}
|
| 35 |
+
)
|
| 36 |
|
| 37 |
response = client.chat.completions.create(
|
| 38 |
messages=messages_prmt,
|
| 39 |
model="llama-3.3-70b-versatile",
|
| 40 |
)
|
| 41 |
+
|
| 42 |
print(response)
|
| 43 |
+
|
| 44 |
LLM_reply = response.choices[0].message.content
|
| 45 |
+
|
| 46 |
+
messages_prmt.append(
|
| 47 |
+
{
|
| 48 |
+
"role": "assistant",
|
| 49 |
+
"content": LLM_reply,
|
| 50 |
+
}
|
| 51 |
+
)
|
| 52 |
|
| 53 |
return LLM_reply
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
iface = gradio.ChatInterface(
|
| 57 |
+
customLLMBot,
|
| 58 |
+
chatbot=gradio.Chatbot(height=300),
|
| 59 |
+
textbox=gradio.Textbox(
|
| 60 |
+
placeholder="Ask me a question related to law"
|
| 61 |
+
),
|
| 62 |
+
title="Lawyer ChatBot",
|
| 63 |
+
description="Chat bot for law assistance",
|
| 64 |
+
theme="soft",
|
| 65 |
+
examples=[
|
| 66 |
+
"hi",
|
| 67 |
+
"What is IPC sections",
|
| 68 |
+
"how to get a bail",
|
| 69 |
+
],
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
iface.launch()
|