Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,32 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
|
|
3 |
import torch
|
4 |
-
from diffusers import FluxPipeline
|
5 |
-
from IPython.display import Audio
|
6 |
from huggingface_hub import login
|
7 |
import os
|
8 |
|
|
|
9 |
api_key = os.getenv("ACCESS_TOKEN")
|
10 |
login(token=api_key)
|
11 |
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
def poet(text):
|
18 |
prompt = 'Make 25 lines, it has to be absolutely 25 lines of text no less no exception, of shakespeare based on this prompt: ' + text
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
st.title("Shakespeare Ai")
|
24 |
st.write("A space made to allow people to create shakespeare like text!")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import transformers
|
4 |
import torch
|
|
|
|
|
5 |
from huggingface_hub import login
|
6 |
import os
|
7 |
|
8 |
+
# load huggingface
|
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 |
+
chat = []
|
16 |
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
19 |
+
model_id,
|
20 |
+
device_map="auto",
|
21 |
+
torch_dtype=dtype,)
|
22 |
|
23 |
def poet(text):
|
24 |
prompt = 'Make 25 lines, it has to be absolutely 25 lines of text no less no exception, of shakespeare based on this prompt: ' + text
|
25 |
+
chat.append({"role": "user", "content": prompt})
|
26 |
+
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
27 |
+
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
28 |
+
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
|
29 |
+
return tokenizer.decode(outputs[0])
|
30 |
|
31 |
st.title("Shakespeare Ai")
|
32 |
st.write("A space made to allow people to create shakespeare like text!")
|