alperugurcan commited on
Commit
68754f6
·
1 Parent(s): a0aeea9

fix: use huggingface_hub 0.26-0.x with explicit router URL

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. requirements.txt +1 -1
app.py CHANGED
@@ -130,12 +130,12 @@ def call_text_model(state: dict[str, Any], action: str, dice: dict[str, Any], tr
130
  hf_token = os.getenv("HF_TOKEN", "").strip()
131
  if hf_token:
132
  try:
133
- client = InferenceClient(provider="hf-inference", api_key=hf_token)
134
  messages = [
135
  {"role": "system", "content": build_system_prompt()},
136
  {"role": "user", "content": build_user_prompt(state, action, dice, trigger_gaslight)},
137
  ]
138
- completion = client.chat_completion(model="Qwen/Qwen2.5-7B-Instruct", messages=messages, max_tokens=450, temperature=0.9)
139
  raw_text = completion.choices[0].message.content
140
  try:
141
  return extract_json(raw_text)
@@ -331,8 +331,8 @@ def generate_image(prompt: str, state: dict[str, Any], dice_total: int) -> str:
331
  hf_token = os.getenv("HF_TOKEN", "").strip()
332
  if hf_token:
333
  try:
334
- client = InferenceClient(provider="hf-inference", api_key=hf_token)
335
- image = client.text_to_image(prompt, model="black-forest-labs/FLUX.1-schnell")
336
  buffered = io.BytesIO()
337
  image.save(buffered, format="PNG")
338
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
 
130
  hf_token = os.getenv("HF_TOKEN", "").strip()
131
  if hf_token:
132
  try:
133
+ client = InferenceClient(model="Qwen/Qwen2.5-7B-Instruct", token=hf_token, api_url="https://router.huggingface.co/hf-inference")
134
  messages = [
135
  {"role": "system", "content": build_system_prompt()},
136
  {"role": "user", "content": build_user_prompt(state, action, dice, trigger_gaslight)},
137
  ]
138
+ completion = client.chat_completion(messages=messages, max_tokens=450, temperature=0.9)
139
  raw_text = completion.choices[0].message.content
140
  try:
141
  return extract_json(raw_text)
 
331
  hf_token = os.getenv("HF_TOKEN", "").strip()
332
  if hf_token:
333
  try:
334
+ client = InferenceClient(model="black-forest-labs/FLUX.1-schnell", token=hf_token, api_url="https://router.huggingface.co/hf-inference")
335
+ image = client.text_to_image(prompt)
336
  buffered = io.BytesIO()
337
  image.save(buffered, format="PNG")
338
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  gradio==4.44.1
2
  starlette<1.0.0
3
  jinja2<3.1.5
4
- huggingface_hub>=1.0.0
5
  requests>=2.32.0
6
 
 
1
  gradio==4.44.1
2
  starlette<1.0.0
3
  jinja2<3.1.5
4
+ huggingface_hub>=0.26.0,<1.0.0
5
  requests>=2.32.0
6