Spaces:
Runtime error
Runtime error
Create streamlit_app.py
Browse files- streamlit_app.py +46 -0
streamlit_app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from diffusers import AudioLDM2Pipeline
|
4 |
+
import scipy
|
5 |
+
import tempfile
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Titel
|
9 |
+
st.set_page_config(page_title="💨 text2fart", page_icon="💀")
|
10 |
+
st.title("💨 text2fart mit Streamlit")
|
11 |
+
st.markdown("Schreib einen beliebigen Text – und hör den furzigen Klang deiner Kreativität! 😆")
|
12 |
+
|
13 |
+
# Prompt-Eingabe
|
14 |
+
prompt = st.text_input("Text eingeben:", placeholder="z. B. 'Apokalyptischer Trompetenfurz bei Sonnenuntergang'")
|
15 |
+
|
16 |
+
# Model laden (nur einmal)
|
17 |
+
@st.cache_resource
|
18 |
+
def load_model():
|
19 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
+
# pipe = DiffusionPipeline.from_pretrained("spaceinvader/text2fart")
|
21 |
+
pipe = AudioLDM2Pipeline.from_pretrained(
|
22 |
+
"spaceinvader/text2fart",
|
23 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
24 |
+
variant="fp16" if torch.cuda.is_available() else None,
|
25 |
+
)
|
26 |
+
return pipe.to(device)
|
27 |
+
|
28 |
+
pipe = load_model()
|
29 |
+
|
30 |
+
# Button
|
31 |
+
if st.button("💥 Furz generieren"):
|
32 |
+
if not prompt.strip():
|
33 |
+
st.warning("Gib bitte etwas ein. Selbst KI braucht Inspiration 😅")
|
34 |
+
else:
|
35 |
+
with st.spinner("Furze werden destilliert..."):
|
36 |
+
result = pipe(prompt, num_inference_steps=20)
|
37 |
+
audio = result["audio"][0]
|
38 |
+
sample_rate = 16000
|
39 |
+
|
40 |
+
# Temporäre WAV-Datei
|
41 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmpfile:
|
42 |
+
scipy.io.wavfile.write(tmpfile.name, rate=sample_rate, data=audio)
|
43 |
+
st.audio(tmpfile.name, format="audio/wav")
|
44 |
+
st.success("Text erfolgreich vertont 💀💨")
|
45 |
+
# Datei am Ende löschen (optional)
|
46 |
+
os.unlink(tmpfile.name)
|