DamarJati commited on
Commit
e08d3ed
·
verified ·
1 Parent(s): f755afb

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -85
app.py DELETED
@@ -1,85 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- import io
4
- import random
5
- import os
6
- from PIL import Image
7
-
8
- API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-3.1"
9
-
10
- API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
11
- headers = {"Authorization": f"Bearer {API_TOKEN}"}
12
-
13
- def query(prompt, is_negative=False, steps=1, cfg_scale=6, seed=None):
14
- payload = {
15
- "inputs": prompt,
16
- "is_negative": is_negative,
17
- "steps": steps,
18
- "cfg_scale": cfg_scale,
19
- "seed": seed if seed is not None else random.randint(-1, 2147483647)
20
- }
21
-
22
- try:
23
- response = requests.post(API_URL, headers=headers, json=payload)
24
- if response.status_code == 200:
25
- image_bytes = response.content
26
- image = Image.open(io.BytesIO(image_bytes))
27
- return image
28
- elif response.status_code == 502:
29
- return "Model is loading. Please wait and try again."
30
- elif response.status_code == 404:
31
- return "Model not found."
32
- else:
33
- return f"Unexpected error: {response.status_code}"
34
- except Exception as e:
35
- return f"An error occurred: {str(e)}"
36
-
37
- css = """
38
- body {
39
- background-color: #fafafa !important;
40
- }
41
- .title {
42
- font-size: 1em !important;
43
- text-align: center;
44
- color: #333;
45
- font-family: 'Helvetica Neue', sans-serif;
46
- text-transform: uppercase;
47
- letter-spacing: 0.1em;
48
- padding: 0.5em 0;
49
- background: transparent;
50
- }
51
-
52
- .title span {
53
- background: -webkit-linear-gradient(45deg, #7ed56f, #28b485);
54
- -webkit-background-clip: text;
55
- -webkit-text-fill-color: transparent;
56
- font-size: 2.5em;
57
- }
58
- .primary.svelte-cmf5ev {
59
- background: -webkit-linear-gradient(45deg, #7ed56f, #28b485) !important;
60
- }
61
- .svelte-15lo0d8 {
62
- flex-direction: column !important;
63
- }
64
- """
65
-
66
- with gr.Blocks(css=css) as Animagine:
67
- gr.HTML(
68
- """
69
- <div style="text-align: center; margin: 0 auto;">
70
- <div style="display: inline-flex; align-items: center; gap: 0.8rem;">
71
- <h1 class="title">
72
- <span>Animagine XL 3.1</span>
73
- </h1>
74
- </div>
75
- </div>
76
- """
77
- )
78
- with gr.Row():
79
- with gr.Column(elem_id="prompt-container"):
80
- text_prompt = gr.Textbox(label="Prompt", value="1girl, c.c., code geass, white shirt, long sleeves, turtleneck, sitting, looking at viewer, eating, pizza, plate, fork, knife, table, chair, table, restaurant, cinematic angle, cinematic lighting, masterpiece, best quality", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
81
- negative_prompt = gr.Textbox(label="Negative Prompt", value="nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, ", lines=1, elem_id="negative-prompt-text-input")
82
- text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
83
- image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
84
- text_button.click(query, inputs=[text_prompt, negative_prompt], outputs=image_output)
85
- Animagine.launch(show_api=False)