Kvikontent commited on
Commit
cf2baf5
1 Parent(s): ea7f5a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -14
app.py CHANGED
@@ -1,21 +1,52 @@
1
- import gradio as gr
2
  import replicate
 
 
 
 
3
 
4
  # Set the replicate API token
5
  import os
6
  os.environ["REPLICATE_API_TOKEN"] = "r8_JSR8xlRoCk6cmq3qEOOThVTn3dAgdPq1bWXdj"
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_output(prompt):
9
- output = replicate.run(
10
- "fofr/sdxl-turbo:6244ebc4d96ffcc48fa1270d22a1f014addf79c41732fe205fb1ff638c409267",
11
- input={"prompt": prompt}
12
- )
13
- return output
14
-
15
- iface = gr.Interface(
16
- fn=generate_output,
17
- inputs=gr.inputs.Textbox(label="Input Prompt"),
18
- outputs=gr.outputs.Textbox(label="Model Output")
19
- )
20
-
21
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import replicate
3
+ import requests
4
+ from PIL import Image
5
+ from io import BytesIO
6
+ import threading
7
 
8
  # Set the replicate API token
9
  import os
10
  os.environ["REPLICATE_API_TOKEN"] = "r8_JSR8xlRoCk6cmq3qEOOThVTn3dAgdPq1bWXdj"
11
 
12
+ model_name = "fofr/sdxl-turbo:6244ebc4d96ffcc48fa1270d22a1f014addf79c41732fe205fb1ff638c409267"
13
+
14
+ class PromptGenerator(threading.Thread):
15
+ def __init__(self, prompt, update_prompt, lock):
16
+ self.prompt = prompt
17
+ self.update_prompt = update_prompt
18
+ self.lock = lock
19
+ super(PromptGenerator, self).__init__()
20
+
21
+ def run(self):
22
+ while True:
23
+ new_prompt = input('Enter a new prompt: ')
24
+ with self.lock:
25
+ self.prompt = new_prompt
26
+ self.update_prompt(self.prompt)
27
+
28
  def generate_output(prompt):
29
+ return replicate.run(model_name, input={"prompt": prompt})
30
+
31
+ st.title("Hugging Face Model Real-time Interface")
32
+
33
+ lock = threading.Lock()
34
+
35
+ prompt = st.text_input("Enter your prompt here")
36
+ update_prompt = st.empty()
37
+
38
+ def update_promt_thread(prompt):
39
+ with lock:
40
+ update_prompt.text(prompt)
41
+
42
+ t = PromptGenerator(prompt, update_prompt, lock)
43
+ t.start()
44
+
45
+ output_url = generate_output(prompt)
46
+
47
+ try:
48
+ response = requests.get(output_url)
49
+ img = Image.open(BytesIO(response.content))
50
+ st.image(img, caption="Model Output", use_column_width=True)
51
+ except Exception as e:
52
+ st.write("Unable to display the image.")