Update app.py
Browse files
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 |
-
|
|
|
35 |
except Exception as e:
|
36 |
-
|
37 |
-
|
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 {
|