Jean888deeg commited on
Commit
c53a0da
·
verified ·
1 Parent(s): d5038cd

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +64 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,66 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ import torch
5
 
6
+ # --- Config ---
7
+ st.set_page_config(page_title="Image Prompt", page_icon="🖼️", layout="centered")
8
+
9
+ # Laad model (gecached)
10
+ @st.cache_resource
11
+ def load_model():
12
+ return pipeline(
13
+ "image-to-text",
14
+ model="llava-hf/llava-v1.6-34b-hf",
15
+ torch_dtype=torch.float16,
16
+ device_map="auto"
17
+ )
18
+
19
+ pipe = load_model()
20
+
21
+ # Stijlen
22
+ STIJLEN = {
23
+ "Realistisch": ", fotorealistisch, 8k, scherp, natuurlijk licht",
24
+ "Anime": ", anime stijl, gedetailleerde ogen, Studio Ghibli, 4k",
25
+ "Olieverf": ", olieverf op doek, impressionistisch, Van Gogh stijl",
26
+ "Cyberpunk": ", cyberpunk, neon lichten, regenachtige straten, Blade Runner",
27
+ "Geen stijl": ""
28
+ }
29
+
30
+ # --- UI ---
31
+ st.title("🖼️ Image → Prompt Generator")
32
+ st.markdown("*Upload een foto, kies een stijl, krijg een perfecte AI-prompt.*")
33
+
34
+ col1, col2 = st.columns([1, 1])
35
+ with col1:
36
+ uploaded_file = st.file_uploader("Kies een afbeelding", type=["png", "jpg", "jpeg"])
37
+ with col2:
38
+ stijl = st.selectbox("Kies een stijl", options=list(STIJLEN.keys()))
39
+
40
+ if uploaded_file:
41
+ image = Image.open(uploaded_file).convert("RGB")
42
+ st.image(image, caption="Jouw afbeelding", use_column_width=True)
43
+
44
+ with st.spinner("Prompt genereren..."):
45
+ result = pipe(image)
46
+ raw_prompt = result[0]["generated_text"]
47
+
48
+ # Optimaliseer
49
+ final_prompt = (
50
+ raw_prompt
51
+ .replace("a photo of", "")
52
+ .replace("an image of", "")
53
+ .strip()
54
+ .capitalize()
55
+ )
56
+ final_prompt += STIJLEN[stijl]
57
+
58
+ st.success("**Prompt:**")
59
+ st.code(final_prompt, language=None)
60
+
61
+ st.download_button(
62
+ "📥 Download prompt",
63
+ final_prompt,
64
+ file_name="prompt.txt",
65
+ mime="text/plain"
66
+ )