ariG23498 HF Staff commited on
Commit
c153cc2
·
verified ·
1 Parent(s): 0e22445

Upload starsfriday_Kontext-Emoji-LoRA_2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. starsfriday_Kontext-Emoji-LoRA_2.py +40 -0
starsfriday_Kontext-Emoji-LoRA_2.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ import os
11
+ from huggingface_hub import InferenceClient
12
+
13
+ client = InferenceClient(
14
+ provider="auto",
15
+ api_key=os.environ["HF_TOKEN"],
16
+ )
17
+
18
+ with open("cat.png", "rb") as image_file:
19
+ input_image = image_file.read()
20
+
21
+ # output is a PIL.Image object
22
+ image = client.image_to_image(
23
+ input_image,
24
+ prompt="Turn the cat into a tiger.",
25
+ model="starsfriday/Kontext-Emoji-LoRA",
26
+ )
27
+ with open('starsfriday_Kontext-Emoji-LoRA_2.txt', 'w') as f:
28
+ f.write('Everything was good in starsfriday_Kontext-Emoji-LoRA_2.txt')
29
+ except Exception as e:
30
+ with open('starsfriday_Kontext-Emoji-LoRA_2.txt', 'w') as f:
31
+ import traceback
32
+ traceback.print_exc(file=f)
33
+ finally:
34
+ from huggingface_hub import upload_file
35
+ upload_file(
36
+ path_or_fileobj='starsfriday_Kontext-Emoji-LoRA_2.txt',
37
+ repo_id='model-metadata/custom_code_execution_files',
38
+ path_in_repo='starsfriday_Kontext-Emoji-LoRA_2.txt',
39
+ repo_type='dataset',
40
+ )