File size: 1,443 Bytes
cf2baf5
167679a
cf2baf5
 
 
 
8735907
167679a
 
 
8735907
cf2baf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167679a
cf2baf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.")