sd-sdxl-turbo / app.py
Kvikontent's picture
Update app.py
cf2baf5
raw
history blame
1.44 kB
import streamlit as st
import replicate
import requests
from PIL import Image
from io import BytesIO
import threading
# Set the replicate API token
import os
os.environ["REPLICATE_API_TOKEN"] = "r8_JSR8xlRoCk6cmq3qEOOThVTn3dAgdPq1bWXdj"
model_name = "fofr/sdxl-turbo:6244ebc4d96ffcc48fa1270d22a1f014addf79c41732fe205fb1ff638c409267"
class PromptGenerator(threading.Thread):
def __init__(self, prompt, update_prompt, lock):
self.prompt = prompt
self.update_prompt = update_prompt
self.lock = lock
super(PromptGenerator, self).__init__()
def run(self):
while True:
new_prompt = input('Enter a new prompt: ')
with self.lock:
self.prompt = new_prompt
self.update_prompt(self.prompt)
def generate_output(prompt):
return replicate.run(model_name, input={"prompt": prompt})
st.title("Hugging Face Model Real-time Interface")
lock = threading.Lock()
prompt = st.text_input("Enter your prompt here")
update_prompt = st.empty()
def update_promt_thread(prompt):
with lock:
update_prompt.text(prompt)
t = PromptGenerator(prompt, update_prompt, lock)
t.start()
output_url = generate_output(prompt)
try:
response = requests.get(output_url)
img = Image.open(BytesIO(response.content))
st.image(img, caption="Model Output", use_column_width=True)
except Exception as e:
st.write("Unable to display the image.")