Update app.py
Browse files
app.py
CHANGED
|
@@ -1,75 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
import os
|
| 5 |
-
import requests
|
| 6 |
|
| 7 |
-
#
|
| 8 |
hf_token = os.getenv("HF_TOKEN")
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
prompt,
|
| 13 |
-
negative_prompt,
|
| 14 |
-
seed,
|
| 15 |
-
randomize_seed,
|
| 16 |
-
width,
|
| 17 |
-
height,
|
| 18 |
-
guidance_scale,
|
| 19 |
-
num_inference_steps,
|
| 20 |
-
progress=gr.Progress(track_tqdm=True),
|
| 21 |
-
):
|
| 22 |
-
if randomize_seed:
|
| 23 |
-
seed = random.randint(0, np.iinfo(np.int32).max)
|
| 24 |
-
|
| 25 |
-
headers = {"Authorization": f"Bearer {hf_token}"}
|
| 26 |
-
payload = {"inputs": prompt} # Start with minimal payload
|
| 27 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 28 |
-
|
| 29 |
-
if response.status_code != 200:
|
| 30 |
-
raise Exception(f"API Error: {response.status_code} - {response.text}")
|
| 31 |
-
|
| 32 |
-
# Assuming the response is an image (binary data)
|
| 33 |
-
image = response.content # Gradio will handle binary image data
|
| 34 |
-
|
| 35 |
-
return image, seed
|
| 36 |
-
|
| 37 |
-
examples = [
|
| 38 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 39 |
-
"An astronaut riding a green horse",
|
| 40 |
-
"A delicious ceviche cheesecake slice",
|
| 41 |
-
]
|
| 42 |
-
|
| 43 |
-
css = """
|
| 44 |
-
#col-container {
|
| 45 |
-
margin: 0 auto;
|
| 46 |
-
max-width: 640px;
|
| 47 |
-
}
|
| 48 |
-
"""
|
| 49 |
-
|
| 50 |
-
with gr.Blocks(css=css) as demo:
|
| 51 |
-
with gr.Column(elem_id="col-container"):
|
| 52 |
-
gr.Markdown(" # Text-to-Image Gradio Template (ZB-Tech Model via API)")
|
| 53 |
-
|
| 54 |
-
with gr.Row():
|
| 55 |
-
prompt = gr.Text(
|
| 56 |
-
label="Prompt",
|
| 57 |
-
show_label=False,
|
| 58 |
-
max_lines=1,
|
| 59 |
-
placeholder="Enter your prompt",
|
| 60 |
-
container=False,
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 64 |
-
|
| 65 |
-
result = gr.Image(label="Result", show_label=False)
|
| 66 |
-
|
| 67 |
-
gr.on(
|
| 68 |
-
triggers=[run_button.click, prompt.submit],
|
| 69 |
-
fn=infer,
|
| 70 |
-
inputs=[prompt],
|
| 71 |
-
outputs=[result],
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
if __name__ == "__main__":
|
| 75 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
+
# Load the API token from the environment variable
|
| 5 |
hf_token = os.getenv("HF_TOKEN")
|
| 6 |
+
interface = gr.load("models/ZB-Tech/Text-to-Image", token=hf_token)
|
| 7 |
|
| 8 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|