Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,31 @@
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import streamlit as st
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
def main():
|
7 |
-
st.title("
|
8 |
-
st.write("
|
9 |
|
10 |
-
# Input
|
11 |
-
|
12 |
|
13 |
-
if st.button("Generate
|
14 |
-
if
|
15 |
-
# Generate
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
st.write(generated_text)
|
21 |
else:
|
22 |
-
st.warning("Please enter a
|
|
|
|
|
|
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
main()
|
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import streamlit as st
|
4 |
+
model_id = "RWKV/rwkv-raven-1b5"
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(model_id).to(0)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
7 |
+
|
8 |
def main():
|
9 |
+
st.title("Raven Text Generator")
|
10 |
+
st.write("Ask a question about ravens and get a response!")
|
11 |
|
12 |
+
# Input question
|
13 |
+
question = st.text_input("Ask a question")
|
14 |
|
15 |
+
if st.button("Generate Response"):
|
16 |
+
if question.strip() != "":
|
17 |
+
# Generate response based on the provided question
|
18 |
+
prompt = f"### Instruction: {question}\n### Response:"
|
19 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(0)
|
20 |
+
output = model.generate(inputs["input_ids"], max_new_tokens=100)
|
21 |
+
generated_text = tokenizer.decode(output[0].tolist(), skip_special_tokens=True)
|
22 |
+
st.markdown("## Generated Response")
|
23 |
st.write(generated_text)
|
24 |
else:
|
25 |
+
st.warning("Please enter a question.")
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
main()
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
main()
|