Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
-
import transformers
|
| 4 |
import torch
|
| 5 |
from huggingface_hub import login
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
#
|
| 9 |
api_key = os.getenv("ACCESS_TOKEN")
|
| 10 |
login(token=api_key)
|
| 11 |
|
| 12 |
-
# setup model
|
| 13 |
-
model_id = "google/gemma-2-2b-it"
|
| 14 |
-
dtype = torch.bfloat16
|
| 15 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 17 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 18 |
-
model.to(device)
|
| 19 |
-
model.eval()
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
outputs
|
| 28 |
-
return tokenizer.decode(outputs[0])
|
| 29 |
|
| 30 |
st.title("Shakespeare Ai")
|
| 31 |
st.write("A space made to allow people to create shakespeare like text!")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline, AutoProcessor, AutoModel
|
|
|
|
| 3 |
import torch
|
| 4 |
from huggingface_hub import login
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
#login
|
| 8 |
api_key = os.getenv("ACCESS_TOKEN")
|
| 9 |
login(token=api_key)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# gemma
|
| 13 |
+
pipe = pipeline(task="text-generation", model="google/gemma-2-2b-it")
|
| 14 |
+
|
| 15 |
+
def poet(prompt):
|
| 16 |
+
messages = [{"role": "user", "content": prompt}]
|
| 17 |
+
outputs = pipe(messages, max_length=1000)
|
| 18 |
+
return outputs[0]["generated_text"][-1]["content"].strip()
|
|
|
|
| 19 |
|
| 20 |
st.title("Shakespeare Ai")
|
| 21 |
st.write("A space made to allow people to create shakespeare like text!")
|