Spaces:
Sleeping
Sleeping
File size: 2,000 Bytes
c61e09a 35580ab c61e09a c55ac76 35580ab c55ac76 12ed36e 42f5647 c61e09a 12ed36e 35580ab c61e09a c55ac76 10dad79 c55ac76 35580ab c61e09a 35580ab c61e09a 35580ab c55ac76 35580ab c55ac76 35580ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import streamlit as st
from transformers import pipeline, AutoProcessor, AutoModel
import torch
from diffusers import FluxPipeline
from IPython.display import Audio
# llama
model_id = "meta-llama/Llama-3.2-3B-Instruct"
pipe = pipeline(
"text-generation",
model=model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a chatbot that writes Shakespeare given a prompt, the text you write should be 25 lines long."},
]
# blackforest
flux = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
flux.enable_model_cpu_offload()
#suno
processor = AutoProcessor.from_pretrained("suno/bark-small")
vc = AutoModel.from_pretrained("suno/bark-small")
def poet(text):
messages.append({"role": "user", "content": text})
outputs = pipe(
messages,
max_new_tokens=256,
)
print(outputs[0]["generated_text"][-1])
def poet_image(poetry):
poetry = 'Create an image based on the following shakespeare like text: ' + poetry
image = flux(
poetry,
height=1024,
width=1024,
guidance_scale=3.5,
num_inference_steps=50,
max_sequence_length=512,
generator=torch.Generator("cpu").manual_seed(0)
).images[0]
return image
def poet_bard(poetry):
inputs = processor(
text=[poetry],
return_tensors="pt",
)
speech_values = vc.generate(**inputs, do_sample=True)
sampling_rate = vc.generation_config.sample_rate
return Audio(speech_values.cpu().numpy().squeeze(), rate=sampling_rate)
st.title("Shakespeare Ai")
st.write("A space made to allow people to create shakespeare like text with images!")
# get prompt
prompt = st.text_input("Enter your prompt: ")
st.button("Generate Shakespeare")
# analyze prompt
shakespeare = poet(prompt)
bard = poet_bard(shakespeare)
img = poet_image(shakespeare)
# write content
st.write(shakespeare)
st.audio(bard)
st.image(img) |