fantaxy commited on
Commit
8b62ce7
โ€ข
1 Parent(s): 263e495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -1,18 +1,18 @@
1
  import gradio as gr
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
 
12
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
13
  client = Client("http://211.233.58.202:7960/")
14
 
15
-
16
  def respond(message, history, system_message, max_tokens, temperature, top_p):
17
  # ์ดˆ๊ธฐ ์„ค์ • ๋ฐ ๋ณ€์ˆ˜ ์ •์˜
18
  system_prefix = "System: ์ž…๋ ฅ์–ด์˜ ์–ธ์–ด์— ๋”ฐ๋ผ ๋™์ผํ•œ ์–ธ์–ด๋กœ ๋‹ต๋ณ€ํ•˜๋ผ."
@@ -27,18 +27,25 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
27
 
28
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์š”์ฒญ
29
  try:
30
- result = client.predict(...)
 
 
 
 
 
 
 
 
 
31
  if 'url' in result:
32
  return result['url']
33
  else:
34
- return "์ด๋ฏธ์ง€ ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."
 
35
  except Exception as e:
36
- return f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
37
- finally:
38
- # ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ
39
- pass
40
 
41
-
42
  theme = "Nymbo/Nymbo_Theme"
43
  css = """
44
  footer {
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
 
4
  import logging
5
+ from gradio_client import Client # ์ด๋ฏธ์ง€ ์ƒ์„ฑ API ํด๋ผ์ด์–ธํŠธ
6
 
7
  # ๋กœ๊น… ์„ค์ •
8
  logging.basicConfig(level=logging.INFO)
9
+
10
  # ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ Hugging Face API ํ† ํฐ์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
11
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
12
 
13
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
14
  client = Client("http://211.233.58.202:7960/")
15
 
 
16
  def respond(message, history, system_message, max_tokens, temperature, top_p):
17
  # ์ดˆ๊ธฐ ์„ค์ • ๋ฐ ๋ณ€์ˆ˜ ์ •์˜
18
  system_prefix = "System: ์ž…๋ ฅ์–ด์˜ ์–ธ์–ด์— ๋”ฐ๋ผ ๋™์ผํ•œ ์–ธ์–ด๋กœ ๋‹ต๋ณ€ํ•˜๋ผ."
 
27
 
28
  # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์š”์ฒญ
29
  try:
30
+ result = client.predict(
31
+ prompt=message,
32
+ seed=123,
33
+ randomize_seed=False,
34
+ width=1024,
35
+ height=576,
36
+ guidance_scale=5,
37
+ num_inference_steps=28,
38
+ api_name="/infer_t2i"
39
+ )
40
  if 'url' in result:
41
  return result['url']
42
  else:
43
+ logging.error("Image generation failed with error: %s", result.get('error', 'Unknown error'))
44
+ return "Failed to generate image."
45
  except Exception as e:
46
+ logging.error("Error during API request: %s", str(e))
47
+ return f"An error occurred: {str(e)}"
 
 
48
 
 
49
  theme = "Nymbo/Nymbo_Theme"
50
  css = """
51
  footer {