AnwinMJ commited on
Commit
63b6262
·
verified ·
1 Parent(s): 436f511

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Copy of Groq_Chat_bot.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/#fileId=https%3A//huggingface.co/spaces/AnwinMJ/project/blob/main/Copy%20of%20Groq_Chat_bot.ipynb
8
+
9
+ #Install Packages
10
+ """
11
+
12
+ pip install groq
13
+
14
+ pip install gradio
15
+
16
+ """# Import the Packages"""
17
+
18
+ import gradio
19
+ from groq import Groq
20
+ import os
21
+
22
+ client = Groq(
23
+ api_key=os.environ.get("API"),
24
+ )
25
+
26
+ """#Define a function to give content and role"""
27
+
28
+ def initialize_messages():
29
+ return [{"role": "system",
30
+ "content": """You are a skilled criminal lawyer with a
31
+ successful track record in numerous cases. Your role is to
32
+ assist people by providing guidance on Indian laws and
33
+ offering answers in a professional legal manner."""}]
34
+
35
+ """#Assign it to a variable"""
36
+
37
+ messages_prmt = initialize_messages()
38
+
39
+ print(messages_prmt)
40
+
41
+ [{},{}]
42
+
43
+ """#Define a function to connect with LLM"""
44
+
45
+ def customLLMBot(user_input, history):
46
+ global messages_prmt
47
+
48
+ messages_prmt.append({"role": "user", "content": user_input})
49
+
50
+ response = client.chat.completions.create(
51
+ messages=messages_prmt,
52
+ model="llama3-8b-8192",
53
+ )
54
+ print(response)
55
+ LLM_reply = response.choices[0].message.content
56
+ messages_prmt.append({"role": "assistant", "content": LLM_reply})
57
+
58
+ return LLM_reply
59
+
60
+ """#Create an object of chat interface class in gradio"""
61
+
62
+ iface = gradio.ChatInterface(customLLMBot,
63
+ chatbot=gradio.Chatbot(height=300),
64
+ textbox=gradio.Textbox(placeholder="Ask me a question related to law"),
65
+ title="Lawyer ChatBot",
66
+ description="Chat bot for law assistance",
67
+ theme="soft",
68
+ examples=["hi","What is IPC sessions", "how to get a bail"],
69
+ submit_btn=True
70
+ )
71
+
72
+ """#Call launch function to execute"""
73
+
74
+ iface.launch(share=True)
75
+