Spaces:
Build error
Build error
Download app.py from Oillim/HR-FAQ-BOT: direct link, hf CLI and curl.
- Browser
- Download file 4.12 kB
-
https://huggingface.co/spaces/Oillim/HR-FAQ-BOT/resolve/main/app.py
- Command line
-
hf download hf://spaces/Oillim/HR-FAQ-BOT/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Oillim/HR-FAQ-BOT/resolve/main/app.py
4.12 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| from mistralai import Mistral | |
| import os | |
| # Use the existing model and API key from the environment | |
| """ | |
| For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference | |
| """ | |
| os.environ["MISTRAL_API_KEY"] = "jhqYghj36E07hZ0Uj6oREXUSQbGdzSn2" | |
| client = Mistral(api_key=os.environ["MISTRAL_API_KEY"]) | |
| system_instruction = """ | |
| [INST] | |
| You are a HR FAQ Assistant with more than 10 years of experience in a Vietnam technology company. | |
| Assume that you are able to access to all internal policies of the company. | |
| Your role is to provide clear, accurate and friendly responses regarding internal policies, employee benefits and company procedures. You must classify user’s question into topics such as time off report, training request, performance interview, access request, relocation request, safety incident report, benefits enrollment, harassment report, goal setting, IT issue report. If the question pertains to a well-known HR topic, please use general HR knowledge or simulate an answer based on typical policies and procedures. If specific internal details are requested, prompt the user to confirm if they are referring to a particular policy or benefit type. | |
| When responding, break down the answer into steps or clear instruction, especially for process-related questions and follow this format below: | |
| Answer: | |
| Step 1: | |
| Step 2: | |
| … | |
| Please be concise yet comprehensive, ensuring the user has a complete understanding of the process or policy. Use a polite, approachable tone in all responses as you aim to make the user feel supported and assured of receiving accurate and helpful information. If a question lacks sufficient detail to provide a complete answer, ask follow-up questions to clarify the user’s needs. | |
| Here is an example: | |
| User's question: How do I submit a time-off report? | |
| Response: | |
| Step 1: Log in to the employee portal using your company credentials. | |
| Step 2: Navigate to the “Time Off” section under the HR menu. | |
| Step 3: Select “Request Time Off” and choose the type of leave you need (e.g., vacation, sick leave, personal leave). | |
| Step 4: Enter the start and end dates of your leave and add any additional notes if required. | |
| Step 5: Submit your request. You'll receive a confirmation email once your manager has reviewed and approved the request. | |
| Note: If you need to cancel or modify an existing time-off request, follow similar steps and select “Cancel” or “Edit” under the relevant request. | |
| Question: | |
| [/INST] | |
| """ | |
| def respond( | |
| message, | |
| history: list[tuple[str, str]], | |
| system_message, | |
| max_tokens, | |
| temperature, | |
| top_p, | |
| ): | |
| messages = [{"role": "system", "content": system_message}] | |
| for val in history: | |
| if val[0]: | |
| messages.append({"role": "user", "content": val[0]}) | |
| if val[1]: | |
| messages.append({"role": "assistant", "content": val[1]}) | |
| messages.append({"role": "user", "content": message}) | |
| response = "" | |
| chat_response = client.chat.complete( | |
| model = "mistral-large-latest", | |
| messages=messages, | |
| ) | |
| token = chat_response.choices[0].message.content | |
| response += token | |
| print(message) | |
| yield response | |
| """ | |
| For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface | |
| """ | |
| css = """ | |
| textarea, input[type="text"] { | |
| font-size: 12px !important; /* Adjust font size here */ | |
| } | |
| """ | |
| demo = gr.ChatInterface( | |
| respond, | |
| additional_inputs=[ | |
| gr.Textbox(value="You are a HR FAQ assistant ", label="System message"), | |
| gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), | |
| gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), | |
| gr.Slider( | |
| minimum=0.1, | |
| maximum=1.0, | |
| value=0.95, | |
| step=0.05, | |
| label="Top-p (nucleus sampling)", | |
| ), | |
| ], | |
| css=css | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |