VashTheStampede123's picture
Update app.py
8b9ef79 verified
# 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')
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()