Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
client = InferenceClient("EvanZhouDev/open-genmoji", token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
6 |
llm = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Define the process function that takes a text prompt and returns an image
|
9 |
def process(prompt):
|
@@ -14,10 +25,14 @@ def process(prompt):
|
|
14 |
]
|
15 |
|
16 |
completion = llm.chat_completion(messages, max_tokens=100)
|
17 |
-
response = completion.get("choices")[0].get("message").get("content").replace("```", "").replace("\n", "")
|
18 |
|
|
|
19 |
print(response)
|
|
|
20 |
image = client.text_to_image(response)
|
|
|
|
|
|
|
21 |
return image
|
22 |
|
23 |
# Create a Gradio Blocks app
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
+
from datetime import datetime
|
5 |
+
|
6 |
|
7 |
client = InferenceClient("EvanZhouDev/open-genmoji", token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
8 |
llm = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
9 |
+
try:
|
10 |
+
os.mkdir("outputs")
|
11 |
+
except FileExistsError:
|
12 |
+
print("Folder already exists.")
|
13 |
+
|
14 |
+
try:
|
15 |
+
os.mkdir("outputs/images")
|
16 |
+
except FileExistsError:
|
17 |
+
print("Folder already exists.")
|
18 |
|
19 |
# Define the process function that takes a text prompt and returns an image
|
20 |
def process(prompt):
|
|
|
25 |
]
|
26 |
|
27 |
completion = llm.chat_completion(messages, max_tokens=100)
|
|
|
28 |
|
29 |
+
response = completion.get("choices")[0].get("message").get("content").replace("```", "").replace("\n", "")
|
30 |
print(response)
|
31 |
+
time = str(datetime.now())
|
32 |
image = client.text_to_image(response)
|
33 |
+
image.save("outputs/images/" + time)
|
34 |
+
with open("outputs/" + time + ".json", "wb") as f:
|
35 |
+
f.write({"prompt": prompt, "refined_prompt": response, "image": "outputs/images/" + time})
|
36 |
return image
|
37 |
|
38 |
# Create a Gradio Blocks app
|