File size: 1,486 Bytes
712c38c
 
 
872b633
712c38c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f9d703
 
 
 
 
712c38c
 
6f9d703
712c38c
 
 
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
# Dependencies
import streamlit as st
from huggingface_hub import InferenceClient
import os

def create_image(prompt):
    """
    Creating an image from a text prompt.
    """
    # output is a PIL.Image object
    image = client.text_to_image(
        prompt,
        model="nerijs/dark-fantasy-illustration-flux"
    )
    
    return image

def Interface():
    """
    Creating a streamlit interface
    """

    st.set_page_config(
    page_title="Dark Fantasy Image Generator",  # Title of the browser tab
    page_icon="πŸ¦β€πŸ”₯",  # Favicon (can be emoji or image URL)
    layout="wide",  # Options: "centered" (default) or "wide"
    initial_sidebar_state="expanded",  # Options: "auto", "expanded", "collapsed"
)

    st.title('Dark Fantasy Image Generator')
    st.caption('A project by Shivam Shinde')
    
    prompt = st.text_area('Image Description', 'Give the description of image that you want to generate')
    if st.button('Generate Image'):
        image = create_image(prompt)
        st.image(image, caption="Image generated by the model: 'nerijs/dark-fantasy-illustration-flux'", use_container_width=True)


if __name__ == "__main__":

    # Getting the API key
    API_KEY = os.getenv("DarkFantasyImageGeneratorApp")

    # Check if the key is retrieved correctly
    if not api_key:
        raise st.error("API Key not found.")

    # Initialize the InferenceClient
    client = InferenceClient(token=API_KEY)

    # Launching the interface
    Interface()