Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,10 @@
|
|
1 |
-
#refer llama recipes for more info https://github.com/huggingface/huggingface-llama-recipes/blob/main/inference-api.ipynb
|
2 |
-
#huggingface-llama-recipes : https://github.com/huggingface/huggingface-llama-recipes/tree/main
|
3 |
import gradio as gr
|
4 |
-
|
5 |
import os
|
6 |
|
7 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
8 |
|
9 |
-
|
10 |
-
base_url="https://api-inference.huggingface.co/v1/",
|
11 |
-
api_key=ACCESS_TOKEN,
|
12 |
-
)
|
13 |
-
|
14 |
-
def respond(
|
15 |
-
message,
|
16 |
-
history: list[tuple[str, str]],
|
17 |
-
system_message,
|
18 |
-
max_tokens,
|
19 |
-
temperature,
|
20 |
-
top_p,
|
21 |
-
):
|
22 |
messages = [{"role": "system", "content": system_message}]
|
23 |
|
24 |
for val in history:
|
@@ -29,41 +15,35 @@ def respond(
|
|
29 |
|
30 |
messages.append({"role": "user", "content": message})
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
max_tokens
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
chatbot = gr.Chatbot(height=600)
|
48 |
|
49 |
-
demo = gr.
|
50 |
-
respond,
|
51 |
-
|
|
|
52 |
gr.Textbox(value="", label="System message"),
|
53 |
-
gr.Slider(minimum=1, maximum=2048, value=512,
|
54 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7,
|
55 |
-
gr.Slider(
|
56 |
-
minimum=0.1,
|
57 |
-
maximum=1.0,
|
58 |
-
value=0.95,
|
59 |
-
step=0.05,
|
60 |
-
label="Top-P",
|
61 |
-
),
|
62 |
-
|
63 |
],
|
64 |
-
|
65 |
-
|
66 |
-
theme="Nymbo/Nymbo_Theme",
|
67 |
)
|
|
|
68 |
if __name__ == "__main__":
|
69 |
-
demo.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
import os
|
4 |
|
5 |
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
6 |
|
7 |
+
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
messages = [{"role": "system", "content": system_message}]
|
9 |
|
10 |
for val in history:
|
|
|
15 |
|
16 |
messages.append({"role": "user", "content": message})
|
17 |
|
18 |
+
# 사용자의 최종 메시지를 포함한 전체 메시지 리스트를 JSON 형식으로 구성
|
19 |
+
data = {
|
20 |
+
"model": "command-r-plus:104b-fp16",
|
21 |
+
"prompt": message,
|
22 |
+
"max_tokens": max_tokens,
|
23 |
+
"temperature": temperature,
|
24 |
+
"top_p": top_p
|
25 |
+
}
|
26 |
+
|
27 |
+
# API 요청 보내기
|
28 |
+
response = requests.post("http://hugpu.ai:7877/api/generate", json=data)
|
29 |
+
generated_text = response.json().get('generated_text', '') # 응답에서 생성된 텍스트 추출
|
30 |
+
|
31 |
+
return generated_text # 생성된 텍스트 반환
|
32 |
+
|
33 |
chatbot = gr.Chatbot(height=600)
|
34 |
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=respond,
|
37 |
+
inputs=[
|
38 |
+
gr.Textbox(label="Your Message"),
|
39 |
gr.Textbox(value="", label="System message"),
|
40 |
+
gr.Slider(minimum=1, maximum=2048, value=512, label="Max new tokens"),
|
41 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, label="Temperature"),
|
42 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, label="Top-P")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
],
|
44 |
+
outputs=chatbot,
|
45 |
+
theme="Nymbo/Nymbo_Theme"
|
|
|
46 |
)
|
47 |
+
|
48 |
if __name__ == "__main__":
|
49 |
+
demo.launch()
|