sevvaliclal's picture
Update src/app.py
1b24fa6 verified
Raw
History Blame Contribute Delete
1.4 kB
# 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"
)