Spaces:
Running
Running
Remove schema-breaking features: use Gradio 3.35.0, remove .then() chains and HTML components
Browse files- app.py +25 -36
- requirements.txt +2 -2
app.py
CHANGED
|
@@ -24,10 +24,10 @@ def initialize_models():
|
|
| 24 |
loop.close()
|
| 25 |
print("β
Models loaded successfully!")
|
| 26 |
|
| 27 |
-
def
|
| 28 |
-
"""Handle chat with character"""
|
| 29 |
if not message or not message.strip():
|
| 30 |
-
return history
|
| 31 |
|
| 32 |
# Initialize if needed
|
| 33 |
if character_manager is None:
|
|
@@ -54,60 +54,49 @@ def chat_with_character(message, character_id, history):
|
|
| 54 |
if history is None:
|
| 55 |
history = []
|
| 56 |
history.append((message, response))
|
| 57 |
-
return history
|
| 58 |
|
| 59 |
except Exception as e:
|
| 60 |
error_msg = f"β Error: {str(e)}"
|
| 61 |
if history is None:
|
| 62 |
history = []
|
| 63 |
history.append((message, error_msg))
|
| 64 |
-
return history
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
with gr.Blocks(
|
| 68 |
-
gr.
|
| 69 |
-
gr.HTML("<p style='text-align: center'>Chat with AI characters!</p>")
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
)
|
| 77 |
|
| 78 |
-
chatbot = gr.Chatbot(
|
|
|
|
| 79 |
|
| 80 |
with gr.Row():
|
| 81 |
-
|
| 82 |
-
label="Your Message",
|
| 83 |
-
placeholder="Type your message here...",
|
| 84 |
-
lines=2
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
with gr.Row():
|
| 88 |
-
submit = gr.Button("Send", variant="primary")
|
| 89 |
clear = gr.Button("Clear")
|
| 90 |
|
| 91 |
-
# Event handlers
|
| 92 |
submit.click(
|
| 93 |
-
|
| 94 |
inputs=[msg, character_dropdown, chatbot],
|
| 95 |
-
outputs=chatbot
|
| 96 |
-
).then(
|
| 97 |
-
lambda: "",
|
| 98 |
-
outputs=msg
|
| 99 |
)
|
| 100 |
|
| 101 |
msg.submit(
|
| 102 |
-
|
| 103 |
inputs=[msg, character_dropdown, chatbot],
|
| 104 |
-
outputs=chatbot
|
| 105 |
-
).then(
|
| 106 |
-
lambda: "",
|
| 107 |
-
outputs=msg
|
| 108 |
)
|
| 109 |
|
| 110 |
-
clear.click(
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
demo.launch(
|
|
|
|
| 24 |
loop.close()
|
| 25 |
print("β
Models loaded successfully!")
|
| 26 |
|
| 27 |
+
def chat_function(message, character_id, history):
|
| 28 |
+
"""Handle chat with character - returns updated history and empty message"""
|
| 29 |
if not message or not message.strip():
|
| 30 |
+
return history, ""
|
| 31 |
|
| 32 |
# Initialize if needed
|
| 33 |
if character_manager is None:
|
|
|
|
| 54 |
if history is None:
|
| 55 |
history = []
|
| 56 |
history.append((message, response))
|
| 57 |
+
return history, ""
|
| 58 |
|
| 59 |
except Exception as e:
|
| 60 |
error_msg = f"β Error: {str(e)}"
|
| 61 |
if history is None:
|
| 62 |
history = []
|
| 63 |
history.append((message, error_msg))
|
| 64 |
+
return history, ""
|
| 65 |
|
| 66 |
+
# Ultra-simple interface to avoid schema issues
|
| 67 |
+
with gr.Blocks() as demo:
|
| 68 |
+
gr.Markdown("# π Roleplay Chat Box")
|
|
|
|
| 69 |
|
| 70 |
+
character_dropdown = gr.Dropdown(
|
| 71 |
+
choices=["moses", "samsung_employee", "jinx"],
|
| 72 |
+
value="moses",
|
| 73 |
+
label="Choose Character"
|
| 74 |
+
)
|
|
|
|
| 75 |
|
| 76 |
+
chatbot = gr.Chatbot()
|
| 77 |
+
msg = gr.Textbox(label="Message", placeholder="Type here...")
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
+
submit = gr.Button("Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
clear = gr.Button("Clear")
|
| 82 |
|
| 83 |
+
# Event handlers - simple format
|
| 84 |
submit.click(
|
| 85 |
+
chat_function,
|
| 86 |
inputs=[msg, character_dropdown, chatbot],
|
| 87 |
+
outputs=[chatbot, msg]
|
|
|
|
|
|
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
msg.submit(
|
| 91 |
+
chat_function,
|
| 92 |
inputs=[msg, character_dropdown, chatbot],
|
| 93 |
+
outputs=[chatbot, msg]
|
|
|
|
|
|
|
|
|
|
| 94 |
)
|
| 95 |
|
| 96 |
+
clear.click(
|
| 97 |
+
lambda: [],
|
| 98 |
+
outputs=[chatbot]
|
| 99 |
+
)
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
| 102 |
demo.launch(
|
requirements.txt
CHANGED
|
@@ -7,8 +7,8 @@ datasets>=2.14.0
|
|
| 7 |
huggingface-hub>=0.19.0
|
| 8 |
safetensors>=0.4.0
|
| 9 |
|
| 10 |
-
# Gradio for Hugging Face Spaces - using
|
| 11 |
-
gradio==3.
|
| 12 |
|
| 13 |
# Backend API
|
| 14 |
fastapi>=0.104.0
|
|
|
|
| 7 |
huggingface-hub>=0.19.0
|
| 8 |
safetensors>=0.4.0
|
| 9 |
|
| 10 |
+
# Gradio for Hugging Face Spaces - using known stable version
|
| 11 |
+
gradio==3.35.0
|
| 12 |
|
| 13 |
# Backend API
|
| 14 |
fastapi>=0.104.0
|