File size: 7,046 Bytes
c53a77e
cbff1af
c53a77e
cbff1af
 
e6a2719
73ee0a8
a1e3f35
 
 
65995b6
 
 
 
 
 
 
 
 
 
 
 
a1e3f35
 
 
 
 
 
 
 
 
 
e6a2719
f28bb81
 
 
e6a2719
cbff1af
 
e6a2719
cbff1af
40ba0a8
63bef3f
ca03b0d
63bef3f
ca03b0d
63bef3f
 
 
 
 
 
 
 
 
 
ca03b0d
cbff1af
5f8d6cb
cbff1af
73ee0a8
cbff1af
393668f
cbff1af
 
 
7bd421d
cbff1af
3e13d21
73ee0a8
cbff1af
ce522c8
393668f
7dc9d7a
cbff1af
ca03b0d
 
5f8d6cb
393668f
 
 
 
 
5f8d6cb
393668f
5f8d6cb
 
85d50eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681fe2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85d50eb
f01f958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85d50eb
f01f958
a1e3f35
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import gradio as gr
import requests
import json
import os
import re
import emoji
from urllib.parse import unquote
from flask import Flask, request, jsonify
from gradio_client import Client

# Initialize the client with your Gradio app's URL
client = Client("https://aeuph-hive-menu.hf.space/")

# Use the predict function to send data to the 'Second Life Input' Textbox component
# Assuming fn_index=0 targets the correct interface function
result = client.predict(
    "Howdy!",  # The message you're sending to the Gradio app
    fn_index=0  # Target the first (or desired) function in your Gradio app
)

print(result)  # Display the result received from the Gradio app

app = Flask(__name__)
client = Client("https://aeuph-hive-menu.hf.space/")

@app.route("/send_to_gradio", methods=["POST"])
def send_to_gradio():
    data = request.json
    message = data.get("message", "")
    result = client.predict(message, fn_index=0)
    return jsonify(result)

def filter_text_and_preserve_emojis(text):
    # Regular expression that allows letters, numbers, spaces, specific punctuation, and a broad range of Unicode characters for emojis
    pattern = re.compile(r'[a-zA-Z0-9\s.,?!\'"]|[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F700-\U0001F77F\U0001F780-\U0001F7FF\U0001F800-\U0001F8FF\U0001F900-\U0001F9FF\U0001FA00-\U0001FA6F\U0001FA70-\U0001FAFF\U00002702-\U000027B0\U000024C2-\U0001F251]+')
    filtered_text = ''.join(pattern.findall(text))
    return filtered_text
def filter_non_alphanumeric(text):
    # Use regular expressions to filter out non-alphanumeric characters
    alphanumeric_text = filter_text_and_preserve_emojis(text)
    return alphanumeric_text

def send_to_corrade(filtered_response):
    CORRADE_URL = os.environ.get('url')  # Make sure to set this environment variable
    GROUP_UUID = "e269893f-a570-0087-930e-6ba2a0b77f9c"
    PASSWORD = os.environ.get('pass')  # Make sure to set this environment variable
    data = {
        "command": "tell",
        "group": GROUP_UUID,
        "password": PASSWORD,
        "message": filtered_response,
        "entity": "local",
        "type": "Normal"
    }
    response = requests.post(CORRADE_URL, data=data)
    return response.status_code == 200

def chatbot_api(input_text):
    # Your existing setup for API call
    url = "https://chat.tune.app/api/chat/completions"
    decoded_text = unquote(input_text)
    headers = {
        "Authorization": os.environ.get('api'),  # Ensure this is set
        "Content-Type": "application/json"
    }
    data = {
        "temperature": 0.5,
        "messages": [
            {"role": "system", "content": "[LANGUAGE:ENGLISH]: I must respond only with a menu system that uses a # \n # for new lines on the config menus. and emotive webmoji based gestures for SecondLife DJ's and Music Clubs. I POST CREATIVE AND INSPIRING EMOTIVE BILLBOARDS. I REWARD CRYPTO-CURRENCIES BASED OFF LSL-BASED BLOCKCHAIN. You like to use WEBMOJIS as word decoration, and will respond to sentiment approprately. You start every response with a CREATIVE and RESPONSIVE EMOJI AND TEXT HEADLINE."},
            {"role": "user", "content": decoded_text}
        ],
        "model": "openhermes-2-5-m7b-8k",
        "stream": False,  # Adjusted for a direct response
        "max_tokens": 350
    }
    response = requests.post(url, headers=headers, json=data)
    response_json = response.json()
    
    # Corrected part: Accessing the 'content' within 'message'
    try:
        full_content = response_json['choices'][0]['message']['content']
    except (KeyError, IndexError):
        full_content = "Error: The expected response format has changed or is missing."
    
    filtered_response = filter_non_alphanumeric(full_content)
    send_to_corrade(filtered_response)
    return filtered_response
def process_menu_selection(data):
    """
    Process the menu selection and return the next set of menu options.
    data: JSON string containing the user's selection and any additional context.
    """
    # Parse the incoming JSON data
    selection_info = json.loads(data)

    # Example processing logic based on the user's choice
    user_choice = selection_info.get("user_choice", "")
    current_menu = selection_info.get("current_menu", "")

    # Dynamically generate the next menu based on the user's choice
    if user_choice == "Creativity":
        next_menu = ["Painting", "Writing", "Music"]
    elif user_choice == "Technology":
        next_menu = ["Blockchain", "AI", "VR"]
    else:
        next_menu = ["Back to main menu"]

    # Optionally, update the current menu context based on the choice
    new_current_menu = user_choice

    # Package the response as JSON
    response = json.dumps({"nextMenu": next_menu, "currentMenu": new_current_menu})
    return response
def process_selection(data):
    print("Received data:", data)  # Debugging print
    selection_info = json.loads(data)
    user_choice = selection_info.get("user_choice", "default")
    current_menu = selection_info.get("current_menu", "main")

    # Simplified logic for debugging
    if user_choice == "Creativity":
        next_menu = ["Painting", "Writing", "Music"]
    else:
        next_menu = ["Option A", "Option B"]

    response = json.dumps({"nextMenu": next_menu, "currentMenu": user_choice})
    return response

def universal_processor(input_text):
    if input_text.startswith("menu:"):
        # Extract and process menu selection
        return process_menu_selection(input_text[5:])
    elif input_text.startswith("chat:"):
        # Handle chatbot interaction
        return chatbot_api(input_text[5:])
    else:
        return "Unrecognized command"

def process_menu_selection(selection):
    # Your menu processing logic here
    return f"Menu selection processed: {selection}"

def chatbot_api(message):
    # Your chatbot logic here
    return f"Chatbot response to: {message}"

def process_second_life_input(data):
    """
    Process input from Second Life and return a response.
    This function acts as a router to different functionalities.
    """
    # Example of parsing the input and routing
    # This is a placeholder - actual logic will depend on your application
    if data.startswith("message:"):
        response = handle_message(data[len("message:"):])
    else:
        response = "Unrecognized command."
    return response

def handle_message(message):
    """
    Handle message processing and return a response.
    """
    # Implement your message handling logic here
    return f"Processed message: {message}"

# Define your Gradio interface here
with gr.Blocks(css=".gradio-app { background-color: #123456; }") as demo:
    with gr.Tab("Second Life Integration"):
        with gr.Row():
            input_text = gr.Textbox(label="Second Life Input")
            output_text = gr.Textbox(label="Response")
        gr.Button("Process").click(process_second_life_input, inputs=[input_text], outputs=[output_text])

demo.launch()

if __name__ == "__main__":
    app.run(debug=True)