File size: 1,755 Bytes
da2134a
0b46e80
da2134a
8f76517
0b46e80
da2134a
0b46e80
dcfbbb8
da2134a
0b46e80
 
 
da2134a
0b46e80
da2134a
 
 
0b46e80
 
da2134a
0b46e80
da2134a
 
 
dcfbbb8
da2134a
 
 
 
 
 
 
 
0b46e80
da2134a
 
 
0b46e80
 
da2134a
 
 
 
0b46e80
da2134a
 
0b46e80
da2134a
 
 
 
 
0b46e80
8f76517
dcfbbb8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
from huggingface_hub import InferenceClient

# Hugging Face API ํ† ํฐ์„ Hugging Face Secrets์—์„œ ๋ถˆ๋Ÿฌ์˜ด
HF_TOKEN = st.secrets["HF_TOKEN"]

# Inference Client ์„ค์ • (GRIN-MoE ๋ชจ๋ธ ์‚ฌ์šฉ)
client = InferenceClient(token=HF_TOKEN)

# Streamlit ํŽ˜์ด์ง€ ์„ค์ •
st.set_page_config(page_title="GRIN-MoE AI Chat", page_icon="๐Ÿค–")
st.title("GRIN-MoE ๋ชจ๋ธ๊ณผ ๋Œ€ํ™”ํ•ด๋ณด์„ธ์š”!")

# ์ฑ„ํŒ… ๊ธฐ๋ก์„ ์„ธ์…˜์— ์ €์žฅ
if 'messages' not in st.session_state:
    st.session_state.messages = []

# ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ›๊ธฐ
user_input = st.text_input("์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”:")

# ์ŠคํŠธ๋ฆฌ๋ฐ ์‘๋‹ต ํ•จ์ˆ˜
def generate_streaming_response(prompt):
    response_text = ""
    for message in client.chat_completion(
        model="microsoft/GRIN-MoE",  # ๋ชจ๋ธ ์ด๋ฆ„์„ ๋ช…์‹œ์ ์œผ๋กœ ์ „๋‹ฌ
        messages=[{"role": "user", "content": prompt}],
        max_tokens=500,
        stream=True
    ):
        delta = message.choices[0].delta.content
        response_text += delta
        yield delta

# ๋Œ€ํ™” ์ฒ˜๋ฆฌ
if user_input:
    st.session_state.messages.append({"role": "user", "content": user_input})

    # AI ์‘๋‹ต์„ ์ŠคํŠธ๋ฆฌ๋ฐ ๋ฐฉ์‹์œผ๋กœ ๋ณด์—ฌ์คŒ
    with st.spinner('AI๊ฐ€ ์‘๋‹ตํ•˜๋Š” ์ค‘...'):
        response_text = ""
        for delta in generate_streaming_response(user_input):
            response_text += delta
            st.write(response_text)

        st.session_state.messages.append({"role": "assistant", "content": response_text})

# ์ด์ „ ๋Œ€ํ™” ๊ธฐ๋ก ์ถœ๋ ฅ
if st.session_state.messages:
    for msg in st.session_state.messages:
        if msg["role"] == "user":
            st.write(f"**์‚ฌ์šฉ์ž:** {msg['content']}")
        else:
            st.write(f"**AI:** {msg['content']}")