Spaces:
Runtime error
Runtime error
File size: 1,395 Bytes
9e4fd66 8f07d0e 1b24fa6 9e4fd66 4674984 1b24fa6 9e4fd66 1b24fa6 9e4fd66 | 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 | # streamlit_app.py
import streamlit as st
# =========================
# Model Class (predict fonksiyonu)
# =========================
class Model:
def __init__(self):
pass
def predict(self, prompt: str) -> str:
svg = f"""<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="180" height="180" fill="lightblue" stroke="black" stroke-width="2"/>
<text x="20" y="100" font-family="Arial" font-size="14">{prompt[:50]}</text>
</svg>"""
return svg
# =========================
# Load model (optional: if using pickle)
# =========================
# Eğer pickle kullanacaksan Model sınıfı tanımlı olmalı
import pickle
from pathlib import Path
model_path = Path("src/svg_model.pkl")
# Eğer pickle ile kaydedildi ve aynı sınıf tanımı var ise:
with open(model_path, "rb") as f:
model = pickle.load(f)
# Alternatif olarak direkt Model() kullanabilirsin
# model = Model()
# =========================
# Streamlit UI
# =========================
st.title("Text to SVG Generator")
prompt = st.text_input("Enter a description:")
if st.button("Generate SVG"):
svg_code = model.predict(prompt)
st.components.v1.html(svg_code, height=250, scrolling=True)
st.download_button(
label="Download SVG",
data=svg_code,
file_name="generated_image.svg",
mime="image/svg+xml"
)
|