Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# ํ์ฌ ์คํฌ๋ฆฝํธ์ ๋๋ ํ ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋ ๊ฒฝ๋ก ์ค์
|
11 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
@@ -48,17 +62,28 @@ def respond(
|
|
48 |
|
49 |
response = ""
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
demo = gr.ChatInterface(
|
64 |
respond,
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient, HfApi
|
3 |
import os
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
|
7 |
+
# Hugging Face ํ ํฐ ํ์ธ
|
8 |
+
hf_token = os.getenv("HF_TOKEN")
|
9 |
+
if not hf_token:
|
10 |
+
raise ValueError("HF_TOKEN ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
11 |
|
12 |
+
# ๋ชจ๋ธ ์ ๋ณด ํ์ธ
|
13 |
+
api = HfApi(token=hf_token)
|
14 |
+
try:
|
15 |
+
model_info = api.model_info("meta-llama/Meta-Llama-3-70B-Instruct")
|
16 |
+
print(f"๋ชจ๋ธ ์ ๋ณด: {model_info}")
|
17 |
+
except Exception as e:
|
18 |
+
print(f"๋ชจ๋ธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐ ์คํจํ์ต๋๋ค: {e}")
|
19 |
+
# ๋์ฒด ๋ชจ๋ธ์ ์ฌ์ฉํ๊ฑฐ๋ ์ค๋ฅ ์ฒ๋ฆฌ๋ฅผ ์ํํ์ธ์.
|
20 |
+
|
21 |
+
# InferenceClient ์ด๊ธฐํ
|
22 |
+
client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=hf_token)
|
23 |
|
24 |
# ํ์ฌ ์คํฌ๋ฆฝํธ์ ๋๋ ํ ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋ ๊ฒฝ๋ก ์ค์
|
25 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
62 |
|
63 |
response = ""
|
64 |
|
65 |
+
try:
|
66 |
+
for message in client.chat_completion(
|
67 |
+
messages,
|
68 |
+
max_tokens=max_tokens,
|
69 |
+
stream=True,
|
70 |
+
temperature=temperature,
|
71 |
+
top_p=top_p,
|
72 |
+
):
|
73 |
+
if message is not None and hasattr(message, 'choices') and len(message.choices) > 0:
|
74 |
+
delta = message.choices[0].delta
|
75 |
+
if delta is not None and hasattr(delta, 'content') and delta.content is not None:
|
76 |
+
token = delta.content.strip("<|END_OF_TURN_TOKEN|>")
|
77 |
+
response += token
|
78 |
+
yield response
|
79 |
+
else:
|
80 |
+
print("Received unexpected message format:", message)
|
81 |
+
except Exception as e:
|
82 |
+
print(f"Error during chat completion: {e}")
|
83 |
+
yield f"์ฃ์กํฉ๋๋ค. ์๋ต ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
84 |
+
|
85 |
+
if not response:
|
86 |
+
yield "์ฃ์กํฉ๋๋ค. ์๋ต์ ์์ฑํ์ง ๋ชปํ์ต๋๋ค."
|
87 |
|
88 |
demo = gr.ChatInterface(
|
89 |
respond,
|