File size: 737 Bytes
9569dec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# Load model directly
import streamlit as st
import transformers
st.title("A Simple Interface for a Language Model")
st.subheader("Input Text")
input_text = st.text_area("Enter your text here", "Type something here...")
if st.button("Generate Response"):
# Initialize tokenizer and model
tokenizer = transformers.AutoTokenizer.from_pretrained("microsoft/phi-2")
model = transformers.AutoModelForCausalLM.from_pretrained("microsoft/phi-2")
# Encode input text
inputs = tokenizer(input_text, return_tensors="pt")
# Generate response
response = model.generate(**inputs, max_length=100, do_sample=True)
# Decode response
st.subheader("Generated Response")
st.write(tokenizer.decode(response[0])) |