Spaces:
Runtime error
Runtime error
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
peft_model_id = "sksayril/bpt-v-4-Bengali"
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(peft_model_id, load_in_8bit=True)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
8 |
+
st.title("Bengali Text Generation")
|
9 |
+
|
10 |
+
prompt = st.text_input("Enter a prompt:", "What is Machine Learning")
|
11 |
+
if st.button("Generate Answer"):
|
12 |
+
with torch.no_grad():
|
13 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
14 |
+
output = model.generate(input_ids, max_length=100)
|
15 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
16 |
+
st.write("Generated Answer:")
|
17 |
+
st.write(generated_text)
|