vfven commited on
Commit
aa93b8f
verified
1 Parent(s): 054beb9

Update agents/specialized.py

Browse files
Files changed (1) hide show
  1. agents/specialized.py +37 -2
agents/specialized.py CHANGED
@@ -8,6 +8,7 @@ import re
8
  import json
9
  import asyncio
10
  import requests
 
11
  from pathlib import Path
12
  from datetime import datetime
13
 
@@ -104,8 +105,42 @@ async def generate_with_gemini(queries, model_name):
104
  return []
105
 
106
  async def generate_with_hf(queries):
107
- # 鈿狅笍 tu l贸gica HF
108
- return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  # 馃煝 FUNCI脫N PRINCIPAL
111
 
 
8
  import json
9
  import asyncio
10
  import requests
11
+ import base64
12
  from pathlib import Path
13
  from datetime import datetime
14
 
 
105
  return []
106
 
107
  async def generate_with_hf(queries):
108
+ urls = []
109
+
110
+ for i, prompt in enumerate(queries[:2]):
111
+ response = requests.post(
112
+ "https://router.huggingface.co/v1/images/generations",
113
+ headers={
114
+ "Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}"
115
+ },
116
+ json={
117
+ "model": "black-forest-labs/FLUX.1-schnell",
118
+ "prompt": prompt,
119
+ "size": "1024x1024"
120
+ }
121
+ )
122
+
123
+ if response.status_code == 200:
124
+ data = response.json()
125
+
126
+ image_base64 = data["data"][0]["b64_json"]
127
+ image_bytes = base64.b64decode(image_base64)
128
+
129
+ DOCS_DIR = Path("data/docs")
130
+ DOCS_DIR.mkdir(exist_ok=True)
131
+
132
+ file_name = f"hf_image_{datetime.now().timestamp()}.png"
133
+ file_path = DOCS_DIR / file_name
134
+
135
+ with open(file_path, "wb") as f:
136
+ f.write(image_bytes)
137
+
138
+ urls.append(f"/docs/{file_name}")
139
+
140
+ else:
141
+ print("HF error:", response.text)
142
+
143
+ return urls
144
 
145
  # 馃煝 FUNCI脫N PRINCIPAL
146