Spaces:
Runtime error
Runtime error
import streamlit as st | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
# Načtení modelu a tokenizeru | |
model_name = "m42-health/Llama3-Med42-8B" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
st.title('Healthcare Chatbot') | |
# Uživatelský vstup | |
user_input = st.text_input("You:", "") | |
if user_input: | |
messages = [ | |
{"role": "system", "content": ( | |
"You are a helpful, respectful and honest medical assistant. " | |
"Always answer as helpfully as possible, while being safe. " | |
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. " | |
"Please ensure that your responses are socially unbiased and positive in nature. " | |
"If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. " | |
"If you don’t know the answer to a question, please don’t share false information." | |
)}, | |
{"role": "user", "content": user_input} | |
] | |
input_text = " ".join([f"{message['role']}: {message['content']}" for message in messages]) | |
input_ids = tokenizer.encode(input_text, return_tensors="pt") | |
# Vygenerování odpovědi | |
output_ids = model.generate(input_ids, max_length=512, do_sample=True, temperature=0.4, top_k=150, top_p=0.75) | |
response = tokenizer.decode(output_ids[0], skip_special_tokens=True) | |
st.text_area("Bot:", response[len(input_text):]) | |