Spaces:
Running
Running
seawolf2357
commited on
Commit
โข
407a575
1
Parent(s):
55aa389
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import logging
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
# ๋ก๊น
์ค์
|
8 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
@@ -32,6 +34,7 @@ class MyClient(discord.Client):
|
|
32 |
response = await generate_response(message.content, history, system_message, 4000, 0.7, 0.95)
|
33 |
await message.channel.send(response)
|
34 |
|
|
|
35 |
# Hugging Face ์ถ๋ก API๋ฅผ ์ฌ์ฉํ์ฌ ์๋ต ์์ฑ
|
36 |
async def generate_response(user_input, history, system_message, max_tokens, temperature, top_p):
|
37 |
system_prefix = """
|
@@ -49,13 +52,13 @@ async def generate_response(user_input, history, system_message, max_tokens, tem
|
|
49 |
messages.append({"role": "assistant", "content": val[1]})
|
50 |
messages.append({"role": "user", "content": user_input})
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
# ๋์ค์ฝ๋ ๋ด ์ธ์คํด์ค ์์ฑ ๋ฐ ์คํ
|
61 |
discord_client = MyClient(intents=intents)
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
5 |
import os
|
6 |
+
import asyncio
|
7 |
+
|
8 |
|
9 |
# ๋ก๊น
์ค์
|
10 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
|
|
34 |
response = await generate_response(message.content, history, system_message, 4000, 0.7, 0.95)
|
35 |
await message.channel.send(response)
|
36 |
|
37 |
+
|
38 |
# Hugging Face ์ถ๋ก API๋ฅผ ์ฌ์ฉํ์ฌ ์๋ต ์์ฑ
|
39 |
async def generate_response(user_input, history, system_message, max_tokens, temperature, top_p):
|
40 |
system_prefix = """
|
|
|
52 |
messages.append({"role": "assistant", "content": val[1]})
|
53 |
messages.append({"role": "user", "content": user_input})
|
54 |
|
55 |
+
# ๋๊ธฐ ํจ์๋ฅผ ๋น๋๊ธฐ๋ก ์ฒ๋ฆฌํ๊ธฐ ์ํ ๋ํผ ์ฌ์ฉ
|
56 |
+
loop = asyncio.get_event_loop()
|
57 |
+
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(messages, max_tokens=max_tokens, stream=False, temperature=temperature, top_p=top_p))
|
58 |
+
return response['choices'][0]['message']['content'] # ์ ์ ํ ์์ฑ ์ฌ์ฉ
|
59 |
+
|
60 |
+
# ๊ธฐ์กด ์ฝ๋๋ ์ ์ง
|
61 |
+
|
62 |
|
63 |
# ๋์ค์ฝ๋ ๋ด ์ธ์คํด์ค ์์ฑ ๋ฐ ์คํ
|
64 |
discord_client = MyClient(intents=intents)
|