fantaxy commited on
Commit
04e9db1
β€’
1 Parent(s): a5a2931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -2,7 +2,10 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
  from gradio_client import Client # 이미지 생성 API ν΄λΌμ΄μ–ΈνŠΈ
 
5
 
 
 
6
  # ν™˜κ²½ λ³€μˆ˜μ—μ„œ Hugging Face API 토큰을 κ°€μ Έμ˜΅λ‹ˆλ‹€.
7
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
8
 
@@ -46,9 +49,18 @@ def respond(
46
  return result['url']
47
  else:
48
  return "이미지 생성에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."
 
 
 
 
 
 
 
 
49
  except Exception as e:
 
50
  return f"였λ₯˜ λ°œμƒ: {str(e)}"
51
-
52
  theme = "Nymbo/Nymbo_Theme"
53
  css = """
54
  footer {
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
  from gradio_client import Client # 이미지 생성 API ν΄λΌμ΄μ–ΈνŠΈ
5
+ import logging
6
 
7
+ # λ‘œκΉ… μ„€μ •
8
+ logging.basicConfig(level=logging.INFO)
9
  # ν™˜κ²½ λ³€μˆ˜μ—μ„œ Hugging Face API 토큰을 κ°€μ Έμ˜΅λ‹ˆλ‹€.
10
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
11
 
 
49
  return result['url']
50
  else:
51
  return "이미지 생성에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."
52
+
53
+ try:
54
+ result = client.predict(...)
55
+ if 'url' in result:
56
+ return result['url']
57
+ else:
58
+ logging.error("이미지 생성 μ‹€νŒ¨: %s", result.get('error', 'μ•Œ 수 μ—†λŠ” 였λ₯˜'))
59
+ return "이미지 생성에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."
60
  except Exception as e:
61
+ logging.error("API μš”μ²­ 쀑 였λ₯˜ λ°œμƒ: %s", str(e))
62
  return f"였λ₯˜ λ°œμƒ: {str(e)}"
63
+
64
  theme = "Nymbo/Nymbo_Theme"
65
  css = """
66
  footer {