Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +45 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,46 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|