Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,28 @@ from huggingface_hub import InferenceClient
|
|
7 |
API_TOKEN = os.getenv("HF_API_TOKEN") # Ensure you've set this environment variable
|
8 |
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
9 |
|
10 |
-
enhancer = InferenceClient(api_key =API_TOKEN)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Function to call Hugging Face API and get the generated image
|
24 |
-
def generate_image(prompt):
|
|
|
|
|
|
|
25 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
26 |
data = {"inputs": prompt}
|
27 |
|
@@ -72,7 +79,7 @@ css = """
|
|
72 |
}
|
73 |
#app-container3 {
|
74 |
background-color: rgba(255, 255, 255, 0.001); /* Corrected to make semi-transparent */
|
75 |
-
max-width:
|
76 |
margin-left: auto;
|
77 |
margin-right: auto;
|
78 |
margin-bottom: 10px;
|
@@ -81,7 +88,7 @@ css = """
|
|
81 |
}
|
82 |
#app-container {
|
83 |
background-color: rgba(255, 255, 255, 0.001); /* Semi-transparent background */
|
84 |
-
max-width:
|
85 |
margin: 0 auto; /* Center horizontally */
|
86 |
padding-bottom: 10px;
|
87 |
border-radius: 25px;
|
@@ -106,9 +113,6 @@ css = """
|
|
106 |
"""
|
107 |
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
# Create Gradio interface
|
113 |
def create_ui():
|
114 |
with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as ui:
|
|
|
7 |
API_TOKEN = os.getenv("HF_API_TOKEN") # Ensure you've set this environment variable
|
8 |
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
9 |
|
|
|
10 |
|
11 |
+
def enhanche_prompt(prompt, system_prompt='You are a prompt enhancer', model="meta-llama/Llama-3.2-1B-Instruct", max_tokens=512, stream=False ):
|
12 |
+
enhancer = InferenceClient(api_key = API_TOKEN)
|
13 |
+
for message in enhancer.chat_completion(
|
14 |
+
model=model,
|
15 |
+
messages=[
|
16 |
+
{"role": "system", "content": system_prompt},
|
17 |
+
{"role": "user", "content": prompt}
|
18 |
+
],
|
19 |
+
max_tokens=max_tokens,
|
20 |
+
stream=stream,
|
21 |
+
):
|
22 |
+
result = message.choices[0].delta.content
|
23 |
+
print(result, end="")
|
24 |
+
return result
|
25 |
+
|
26 |
|
27 |
# Function to call Hugging Face API and get the generated image
|
28 |
+
def generate_image(prompt, enhance=False]):
|
29 |
+
if enhance:
|
30 |
+
prompt = enhanche_prompt(prompt)
|
31 |
+
|
32 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
33 |
data = {"inputs": prompt}
|
34 |
|
|
|
79 |
}
|
80 |
#app-container3 {
|
81 |
background-color: rgba(255, 255, 255, 0.001); /* Corrected to make semi-transparent */
|
82 |
+
max-width: 300px;
|
83 |
margin-left: auto;
|
84 |
margin-right: auto;
|
85 |
margin-bottom: 10px;
|
|
|
88 |
}
|
89 |
#app-container {
|
90 |
background-color: rgba(255, 255, 255, 0.001); /* Semi-transparent background */
|
91 |
+
max-width: 300px;
|
92 |
margin: 0 auto; /* Center horizontally */
|
93 |
padding-bottom: 10px;
|
94 |
border-radius: 25px;
|
|
|
113 |
"""
|
114 |
|
115 |
|
|
|
|
|
|
|
116 |
# Create Gradio interface
|
117 |
def create_ui():
|
118 |
with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as ui:
|