Download app.py from AnwinMJ/project: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/AnwinMJ/project/resolve/main/app.py
- Command line
-
hf download hf://spaces/AnwinMJ/project/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AnwinMJ/project/resolve/main/app.py
1.96 kB
| # -*- coding: utf-8 -*- | |
| """Copy of Groq_Chat_bot.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/#fileId=https%3A//huggingface.co/spaces/AnwinMJ/project/blob/main/Copy%20of%20Groq_Chat_bot.ipynb | |
| #Install Packages | |
| """ | |
| """# Import the Packages""" | |
| import gradio | |
| from groq import Groq | |
| import os | |
| client = Groq( | |
| api_key=os.environ.get("API"), | |
| ) | |
| """#Define a function to give content and role""" | |
| 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."""}] | |
| """#Assign it to a variable""" | |
| messages_prmt = initialize_messages() | |
| print(messages_prmt) | |
| [{},{}] | |
| """#Define a function to connect with LLM""" | |
| 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="llama3-8b-8192", | |
| ) | |
| print(response) | |
| LLM_reply = response.choices[0].message.content | |
| messages_prmt.append({"role": "assistant", "content": LLM_reply}) | |
| return LLM_reply | |
| """#Create an object of chat interface class in gradio""" | |
| 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 sessions", "how to get a bail"], | |
| submit_btn=True | |
| ) | |
| """#Call launch function to execute""" | |
| iface.launch(share=True) | |