pravaahiman
commited on
Commit
•
4375924
1
Parent(s):
dc2acb8
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model():
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B")
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B")
|
9 |
+
return tokenizer, model
|
10 |
+
|
11 |
+
tokenizer, model = load_model()
|
12 |
+
|
13 |
+
# Streamlit app UI
|
14 |
+
st.title("Qwen-7B Text Generation")
|
15 |
+
|
16 |
+
# Text input
|
17 |
+
user_input = st.text_area("Enter your text:")
|
18 |
+
|
19 |
+
# Generate text on button click
|
20 |
+
if st.button("Generate"):
|
21 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
22 |
+
outputs = model.generate(**inputs, max_length=100)
|
23 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
+
st.write("Generated Text:")
|
25 |
+
st.write(generated_text)
|