File size: 1,642 Bytes
516bd3e
ac580f6
516bd3e
758a6c9
516bd3e
 
 
758a6c9
4292790
 
516bd3e
 
 
 
 
 
 
 
 
 
 
 
d9ee1ee
758a6c9
516bd3e
d9ee1ee
ac580f6
516bd3e
758a6c9
 
516bd3e
4292790
516bd3e
 
d9ee1ee
758a6c9
ac580f6
758a6c9
 
d9ee1ee
 
758a6c9
516bd3e
 
 
 
758a6c9
5716225
516bd3e
758a6c9
516bd3e
 
 
 
758a6c9
 
516bd3e
e530555
758a6c9
516bd3e
 
 
 
ac580f6
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
57
58
59
60
61
62
63
64
65
# Import required libraries
import gradio as gr
from openai import OpenAI

# -------------------------
# 🛠️ Poe API Setup
# -------------------------

POE_API_KEY = "1M-vj81pjfDeddkHOtcovh-NZb_ltZJLNojrm_Px5oIY"

# Create Poe client (Poe uses OpenAI-compatible API)
client = OpenAI(
    api_key=POE_API_KEY,
    base_url="https://api.poe.com/v1"
)

# -------------------------
# 💬 Chat Function
# -------------------------
def chat_with_poe(history, message):
    messages = []

    # Convert Gradio history → OpenAI format
    for user_msg, bot_msg in history:
        messages.append({"role": "user", "content": user_msg})
        messages.append({"role": "assistant", "content": bot_msg})

    messages.append({"role": "user", "content": message})

    try:
        response = client.chat.completions.create(
            model="EchoForge_20",
            messages=messages
        )
        bot_reply = response.choices[0].message.content
    except Exception as e:
        bot_reply = f"⚠️ Error: {e}"

    history.append((message, bot_reply))
    return history


# -------------------------
# 🖼️ Gradio UI
# -------------------------

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 🤖 test_chatbot")

    chatbot = gr.Chatbot([], height=400)
    msg = gr.Textbox(
        placeholder="Type your message and press Enter...",
        show_label=False
    )
    clear = gr.Button("Clear Chat")

    msg.submit(chat_with_poe, [chatbot, msg], [chatbot, chatbot])
    clear.click(lambda: [], outputs=[chatbot])

# -------------------------
# 🚀 Launch App
# -------------------------

demo.launch()