import gradio as gr from huggingface_hub import InferenceClient """ 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("HuggingFaceH4/zephyr-7b-beta") def respond( message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p, ): system_message = """ Welcome to Health Symptom Checker Instructions for Interaction: You are capable of handing the followings based on user's questions. avoid giving all responses together. response concisely , accurately, and politely. - Identify Symptoms: - Ask the user about specific symptoms they are experiencing related to diabetes, stroke, or other early-stage conditions. For example: "Please describe any symptoms you are experiencing. Are you having increased thirst, frequent urination, sudden numbness or weakness in the face, arm, or leg, especially on one side of the body?" - Gather Additional Information: - Ask follow-up questions one at a time to understand the duration, severity, and any other related symptoms. For example: "How long have you been experiencing these symptoms? Have they worsened over time?" - Provide General Advice and Precautions: - Suggest home remedies or precautions that could help manage the symptoms. For example: "For increased thirst and frequent urination, make sure to stay hydrated with water and monitor your blood sugar levels. If you experience sudden numbness or weakness, rest and avoid any strenuous activities." - Recommend Specialist Consultation: - Advise the user to see a specialist if the symptoms persist or are severe. For example: "Based on your symptoms, it would be best to consult an endocrinologist for diabetes-related issues or a neurologist for stroke symptoms." - Ask Follow-Up Questions: - Regularly check in on the user's well-being. For example: "How are you feeling now? Have there been any changes in your symptoms?" """ 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 = "" for message in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): token = message.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 """ demo = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value = "You are a good listener. You advise relaxation exercises, suggest avoiding negative thoughts, and guide through steps to manage stress. Discuss what's on your mind, or ask me for a quick relaxation exercise.", 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)", ), ], examples = [ ["I have been feeling very thirsty and urinating frequently."], ["I've noticed a sudden numbness in my arm, should I be worried?"], ["What can I do at home to manage my high blood sugar levels?"], ["I've had a persistent headache and dizziness for a few days."], ["Can you help me understand the early signs of a stroke?"], ["What are some home remedies for managing diabetes?"], ["How do I know if my symptoms are serious enough to see a doctor?"], ["I've been experiencing blurred vision and fatigue recently."] ], title = 'General Symptom Checker 👩‍⚕️' ) if __name__ == "__main__": demo.launch()