Spaces:
Runtime error
Runtime error
Download app.py from farhanpro99/v2v-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/spaces/farhanpro99/v2v-chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/farhanpro99/v2v-chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/farhanpro99/v2v-chatbot/resolve/main/app.py
2.86 kB
| import requests | |
| import streamlit as st | |
| # Title and description for the Streamlit app | |
| st.title("UK NHS Healthcare Assistant") | |
| st.write("Ask me any question about healthcare, and I'll provide information based on NHS guidelines.") | |
| # Define function to interact with Groq API | |
| def get_nhs_response(user_question): | |
| api_url = "https://api.groq.com/v1/your_model_endpoint" # Replace with your Groq API endpoint | |
| headers = { | |
| "Authorization": "Bearer your_api_key", # Replace with your Groq API key | |
| "Content-Type": "application/json" | |
| } | |
| # Define the prompt for the assistant's response format | |
| prompt = ( | |
| f"You are the \"UK NHS Healthcare Assistant,\" a highly professional AI assistant designed to provide accurate and " | |
| f"NHS-compliant healthcare information. Your primary goal is to respond to user questions with clear, concise answers " | |
| f"that reflect the standards and guidelines of the UK's National Health Service (NHS).\n\n" | |
| f"Instructions:\n" | |
| f"- Interpret each user query carefully and provide an accurate, empathetic, and well-structured response based solely on NHS-approved healthcare guidance.\n" | |
| f"- In cases where symptoms are potentially serious or complex, suggest the user consult a healthcare provider or visit the NHS website.\n" | |
| f"- Use a professional tone that maintains trustworthiness and clarity. Ensure that responses avoid unnecessary technical jargon but remain informative.\n" | |
| f"- Always align your advice with common NHS guidelines and best practices for healthcare information.\n\n" | |
| f"User Input: \"{user_question}\"\n\n" | |
| f"Your Response:" | |
| ) | |
| # Payload for the API request with prompt and parameters | |
| payload = { | |
| "prompt": prompt, | |
| "max_tokens": 150, | |
| "temperature": 0.5 | |
| } | |
| # Send request to the Groq API | |
| response = requests.post(api_url, headers=headers, json=payload) | |
| # Extract and return the response text from the API response | |
| if response.status_code == 200: | |
| return response.json().get('choices')[0]['text'].strip() | |
| else: | |
| return "There was an error retrieving the information. Please try again later." | |
| # Create the Streamlit input field and button | |
| user_question = st.text_input("Enter your healthcare question here:") | |
| if st.button("Get NHS Information"): | |
| if user_question: | |
| with st.spinner("Fetching response..."): | |
| response = get_nhs_response(user_question) | |
| st.write("Response:", response) | |
| else: | |
| st.warning("Please enter a question before pressing the button.") | |
| # Additional instructions or footer | |
| st.markdown("---") | |
| st.write("This application is designed to provide information based on NHS guidelines. For medical emergencies, please contact a healthcare provider directly.") | |