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