Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
model_id = "meta-llama/Llama-3.2-3B-Instruct"
|
| 7 |
+
pipe = pipeline(
|
| 8 |
+
"text-generation",
|
| 9 |
+
model=model_id,
|
| 10 |
+
torch_dtype=torch.bfloat16,
|
| 11 |
+
device_map="auto",
|
| 12 |
+
)
|
| 13 |
+
messages = [
|
| 14 |
+
{"role": "system", "content": "You are a chatbot that writes Shakespeare given a prompt, the text you write should be 25 lines long."},
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
def poet(text):
|
| 18 |
+
messages.append({"role": "user", "content": text})
|
| 19 |
+
outputs = pipe(
|
| 20 |
+
messages,
|
| 21 |
+
max_new_tokens=256,
|
| 22 |
+
)
|
| 23 |
+
print(outputs[0]["generated_text"][-1])
|
| 24 |
+
|
| 25 |
+
st.title("Shakespeare Ai")
|
| 26 |
+
st.write("A space made to allow people to create shakespeare like text with images!")
|
| 27 |
+
prompt = st.text_input("Enter your prompt: ")
|
| 28 |
+
st.button("Generate Shakespeare")
|
| 29 |
+
st.write(poet(prompt))
|