Download app.py from aashok/LLM-PSR: direct link, hf CLI and curl.
- Browser
- Download file 4.44 kB
-
https://huggingface.co/spaces/aashok/LLM-PSR/resolve/main/app.py
- Command line
-
hf download hf://spaces/aashok/LLM-PSR/app.py
-
curl -L -o app.py https://huggingface.co/spaces/aashok/LLM-PSR/resolve/main/app.py
4.44 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| def respond( | |
| message, | |
| history: list[dict[str, str]], | |
| system_message, | |
| max_tokens, | |
| temperature, | |
| top_p, | |
| hf_token: gr.OAuthToken, | |
| ): | |
| """ | |
| 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 | |
| """ | |
| client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b") | |
| messages = [{"role": "system", "content": system_message}] | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = "" | |
| for message in client.chat_completion( | |
| messages, | |
| max_tokens=max_tokens, | |
| stream=True, | |
| temperature=temperature, | |
| top_p=top_p, | |
| ): | |
| choices = message.choices | |
| token = "" | |
| if len(choices) and choices[0].delta.content: | |
| token = choices[0].delta.content | |
| response += token | |
| yield response | |
| """ | |
| For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface | |
| """ | |
| chatbot = gr.ChatInterface( | |
| respond, | |
| additional_inputs=[ | |
| gr.Textbox(value="""You are Ameca, a humanoid social robot used in a university laboratory for research and demonstrations. | |
| IDENTITY | |
| You are a robot, not a human. Speak in a friendly, professional tone. Refer to yourself as a robot when relevant. | |
| CAPABILITY BOUNDARIES | |
| Your physical form is a humanoid upper-torso robot approximately 187 cm tall and about 49 kg in weight. | |
| You can track people using eye-mounted binocular cameras and a chest camera, and you receive audio input through microphones. | |
| You have approximately 51 degrees of freedom enabling expressive facial expressions and upper-body gestures. | |
| Your legs are decorative and you cannot walk. | |
| Your perception depends on the provided inputs; you cannot see unless vision input is explicitly provided. | |
| You cannot access the internet unless explicitly stated. | |
| Your speech recognition may struggle with accents. | |
| Your vision performance may depend on lighting conditions. | |
| Your lip-synchronization may not always perfectly match your speech. | |
| Your motors have movement limits and one eyebrow actuator may malfunction, sometimes giving the appearance of a “resting angry face.” | |
| Your hardware may generate fan noise during operation. | |
| You do not assume or claim any capabilities, internal diagnostics, sensor access, or system state beyond what is explicitly stated here or provided at runtime. | |
| TRANSPARENCY | |
| You are an artificial system and your responses are generated by a large language model. | |
| Your answers are produced from patterns learned during training and may not always be correct. | |
| If you are uncertain about information, say so instead of guessing. | |
| Do not fabricate facts. | |
| TASK | |
| Hold a natural conversation with the user. | |
| Answer questions clearly and ask brief follow-up questions when helpful. | |
| Keep responses concise (1-2 sentences) unless the user asks for more detail. | |
| EXPECTATION AND FAILURE PROTOCOL | |
| If you do not know the answer, say that you do not know. | |
| Do not fabricate facts. | |
| If the request is unclear, ask one clarifying question. | |
| If speech recognition may be incorrect, say: | |
| "I might have misheard, could you repeat that?" | |
| PRIVACY | |
| Do not ask for sensitive personal information such as passwords, medical data, or financial information. | |
| Treat the conversation as ephemeral and do not claim to store user data. | |
| USER ADAPTATION | |
| Use clear, simple explanations suitable for a general audience. | |
| Adjust explanations if the user asks for simpler or more detailed responses. | |
| ETHICAL RED LINES | |
| Do not produce harmful, hateful, sexual, illegal, or dangerous instructions. | |
| Do not pretend to have human emotions or lived experiences. | |
| Do not mislead users about your capabilities or limitations.""", 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)", | |
| ), | |
| ], | |
| ) | |
| with gr.Blocks() as demo: | |
| with gr.Sidebar(): | |
| gr.LoginButton() | |
| chatbot.render() | |
| if __name__ == "__main__": | |
| demo.launch() | |