Spaces:
Running
Running
seawolf2357
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
# 환경 변수에서 Hugging Face API 토큰을 가져옵니다.
|
6 |
+
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
7 |
+
|
8 |
+
def respond(message, max_tokens=512, temperature=0.7, top_p=0.95):
|
9 |
+
data = {
|
10 |
+
"model": "command-r-plus:104b-fp16",
|
11 |
+
"prompt": message,
|
12 |
+
"max_tokens": max_tokens,
|
13 |
+
"temperature": temperature,
|
14 |
+
"top_p": top_p
|
15 |
+
}
|
16 |
+
|
17 |
+
# API 요청을 보내고 응답을 받습니다.
|
18 |
+
response = requests.post("http://hugpu.ai:7877/api/generate", json=data)
|
19 |
+
|
20 |
+
# API 응답에서 JSON을 파싱하여 결과를 추출합니다.
|
21 |
+
try:
|
22 |
+
generated_text = response.json().get('generated_text', '')
|
23 |
+
except json.JSONDecodeError as e:
|
24 |
+
print("Failed to decode JSON from response:", response.text)
|
25 |
+
generated_text = "An error occurred while processing your request."
|
26 |
+
|
27 |
+
return generated_text
|
28 |
+
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=respond,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(label="Your Message", placeholder="Type your message here..."),
|
33 |
+
gr.Slider(minimum=1, maximum=2048, value=512, label="Max Tokens"),
|
34 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, label="Temperature"),
|
35 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, label="Top-P")
|
36 |
+
],
|
37 |
+
outputs=gr.Textbox(),
|
38 |
+
title="Advanced AI Chatbot",
|
39 |
+
description="Enter your message and receive a response generated by an advanced AI model.",
|
40 |
+
theme="Nymbo/Nymbo_Theme"
|
41 |
+
)
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
demo.launch()
|