File size: 4,738 Bytes
fc11d8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import streamlit as st
from PIL import Image
import yaml
import requests
import os
from datetime import datetime
import json

# Function to load YAML files
def load_yaml_file(file_path):
    with open(file_path, "r") as file:
        return yaml.safe_load(file)

# Initialize app configuration
st.set_page_config(page_title="Multi-tab Image App", layout="wide")

# Output folder
output_folder = "output"
os.makedirs(output_folder, exist_ok=True)

# Placeholder for the image display
image_placeholder = st.empty()

# Load Chatbot system prompts
chatbot_prompts = load_yaml_file("system_prompts.yaml")

# Tabs
tab_names = ["Image Generation", "Chat/Prompt Enhancement", "AIvatar ChatBot", "Story Generation", "Gallery", "System Prompts Editor"]
tabs = st.tabs(tab_names)

# Image Generation Tab
with tabs[0]:
    st.header("Image Generation")
    
    # Input fields
    prompt = st.text_input("Prompt")
    seed = st.slider("Seed", min_value=0, max_value=1000000, value=0)
    randomize_seed = st.checkbox("Randomize seed", value=True)
    width = st.slider("Width", min_value=256, max_value=1024, value=1024)
    height = st.slider("Height", min_value=256, max_value=1024, value=1024)
    steps = st.slider("Inference steps", min_value=1, max_value=50, value=4)
    
    # Generate Image button
    if st.button("Generate Image"):
        st.info("Generating image...")
        # Simulate the image generation process
        try:
            # Replace with your own API call
            result = {"image_path": "sample_image.png", "generated_seed": seed}
            
            image_path = result['image_path']
            image = Image.open(image_path)
            image_placeholder.image(image)
            
            # Save image
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            prompt_slug = "_".join(prompt.replace(':', '').replace("'", '').replace('"', '').replace(',', '').replace('.', '').replace('*', '##').strip().split()[:10]).lower()
            filename = f"{timestamp}_{prompt_slug}.png"
            file_path = os.path.join(output_folder, filename)
            image.save(file_path)
            st.success(f"Image saved as {file_path}")
        except Exception as e:
            st.error(f"An error occurred: {str(e)}")

# Chat/Prompt Enhancement Tab
with tabs[1]:
    st.header("Chat/Prompt Enhancement")
    
    # Chat history and user input
    chat_history = st.text_area("Chat History", height=300)
    user_input = st.text_input("Your Input")
    
    # Buttons for sending message or listening
    if st.button("Send"):
        st.info("Sending message...")
        # Simulate sending a message to the chatbot
    if st.button("Listen"):
        st.info("Listening...")

# AIvatar ChatBot Tab
with tabs[2]:
    st.header("AIvatar ChatBot")
    
    # Chat history and user input
    chat_history_ai = st.text_area("Chat History", height=300)
    user_input_ai = st.text_input("Your Input")
    
    # Send button
    if st.button("Send AI Message"):
        st.info("Sending message to AIvatar ChatBot...")
        # Simulate sending a message to the chatbot

# Story Generation Tab
with tabs[3]:
    st.header("Story Generation")
    
    # Input fields for story generation
    story_prompt = st.text_input("Story Prompt")
    story_style = st.text_input("Story Style")
    
    # Generate Story button
    if st.button("Generate Story"):
        st.info("Generating story...")
        # Simulate story generation process
        st.text_area("Story Output", "Generated story will appear here...", height=300)
        
    # Save to PDF button
    if st.button("Save to PDF"):
        st.info("Saving story to PDF...")

# Gallery Tab
with tabs[4]:
    st.header("Gallery")
    
    # Load and display images from the output folder
    images = [f for f in os.listdir(output_folder) if f.endswith(".png")]
    if images:
        st.image([os.path.join(output_folder, img) for img in images], width=150)
    else:
        st.info("No images found in the gallery.")

# System Prompts Editor Tab
with tabs[5]:
    st.header("System Prompts Editor")
    
    # Select and edit prompts
    prompt_keys = list(chatbot_prompts.keys())
    selected_prompt_key = st.selectbox("Select a prompt to edit", prompt_keys)
    selected_prompt_text = st.text_area("Prompt Text", chatbot_prompts[selected_prompt_key], height=200)
    
    # Save prompt button
    if st.button("Save Prompt"):
        chatbot_prompts[selected_prompt_key] = selected_prompt_text
        # Save the updated prompts back to the YAML file
        with open("system_prompts.yaml", "w") as file:
            yaml.safe_dump(chatbot_prompts, file)
        st.success(f"Prompt '{selected_prompt_key}' saved successfully!")