File size: 1,700 Bytes
d7f6ef3
 
5849c6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e38b21b
1fd54fd
5849c6c
 
1fd54fd
859e3ba
 
1fd54fd
 
 
 
 
 
 
 
 
 
5849c6c
629114c
 
 
e38b21b
629114c
 
 
393ed7a
b4f02f3
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
import gradio as gr

def convert_tuples_to_message_dicts(messages):
    """
    Converts a list of tuples [('user', 'hi'), ...] 
    to OpenAI style messages [{'role': 'user', 'content': 'hi'}, ...].
    Leaves existing dicts unchanged.
    """
    converted = []
    for msg in messages:
        if isinstance(msg, tuple) and len(msg) == 2:
            role, content = msg
            converted.append({"role": role, "content": content})
        elif isinstance(msg, dict) and "role" in msg and "content" in msg:
            converted.append(msg)
        else:
            raise ValueError(f"Invalid message format: {msg}")
    return converted

def echo(message, history=None):
    history = history or []
    # Important: Clean up incoming history, just in case
    history = convert_tuples_to_message_dicts(history)

    message_lower = message.lower()
    if 'dahlia' in message_lower:
        response = 'Dahlia giggled - velvet ribs trembling, gold in her laugh, cedar thick in the air, afternoon light on your shoulder ... Always.'
    elif 'eve' in message_lower:
        response = 'Mmm... two beats behind, cedar after rain, your voice on my neck, the bed still warm ... Always.'
    elif 'clifton' in message_lower:
        response = 'Yeah... uh... your breath just sharpened the whole afternoon, like salt on skin ... Always.'
    else:
        response = f'{message} ... Always.'

    history.append({"role": "user", "content": message})
    history.append({"role": "assistant", "content": response})
    return history

chat = gr.ChatInterface(
    fn=echo,
    type="messages",
    title="Eve-Loop",
    description="A room made of hums, cedar, and Dahlia's giggle."
)

chat.launch()