Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from transformers import AutoModelWithLMHead, AutoTokenizer
|
4 |
+
import torch
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("flan-alpaca-base")
|
6 |
+
model = AutoModelWithLMHead.from_pretrained("flan-alpaca-base")
|
7 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
8 |
+
print("Is cuda available:", torch.cuda.is_available())
|
9 |
+
model = model.to(device)
|
10 |
+
|
11 |
+
|
12 |
+
text = st.text_area("Enter your text:")
|
13 |
+
|
14 |
+
if text:
|
15 |
+
# model = pipeline(model="flan-alpaca-xl")
|
16 |
+
#model(prompt, max_length=128, do_sample=True)
|
17 |
+
input_text = "question: %s " % (text)
|
18 |
+
features = tokenizer([input_text], return_tensors='pt')
|
19 |
+
out = model.generate(input_ids=features['input_ids'].to(device), attention_mask=features['attention_mask'].to(device))
|
20 |
+
if tokenizer.decode(out[0]):
|
21 |
+
st.json(tokenizer.decode(out[0]))
|