Tester / app.py
Tabish009's picture
Create app.py
99abe2b verified
raw
history blame
1.3 kB
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the Biomistral 7b model and tokenizer
model_name = "biomistral/Biomistral-7b"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
# Define the text generation function
def generate_text(prompt, max_length=500, num_return_sequences=1, temperature=0.7):
input_ids = tokenizer.encode(prompt, return_tensors="pt")
output = model.generate(
input_ids,
max_length=max_length,
num_return_sequences=num_return_sequences,
temperature=temperature,
pad_token_id=tokenizer.eos_token_id,
)
generated_text = tokenizer.batch_decode(output, skip_special_tokens=True)
return generated_text
# Streamlit app
def main():
st.title("Doctor Chatbot (Powered by Biomistral 7b)")
st.write("Welcome to the Doctor Chatbot. Please describe your symptoms or ask a medical question, and I'll provide a response.")
user_input = st.text_area("Enter your symptoms or question:")
if user_input:
with st.spinner("Generating response..."):
generated_text = generate_text(user_input)
st.write(generated_text[0])
if __name__ == "__main__":
main()