Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,18 @@ from assistant import get_assistant_response
|
|
| 5 |
# Load model pipeline
|
| 6 |
pipe = load_model()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Gradio UI
|
| 9 |
demo = gr.Interface(
|
| 10 |
-
fn=
|
| 11 |
inputs=[
|
| 12 |
gr.Textbox(lines=2, placeholder="e.g. Open Chrome or Take a screenshot", label="🧾 Command"),
|
| 13 |
gr.Checkbox(label="🛠️ Execute command (if possible)")
|
|
@@ -15,9 +24,10 @@ demo = gr.Interface(
|
|
| 15 |
outputs="text",
|
| 16 |
title="🧠 Smart AI Assistant",
|
| 17 |
description=(
|
| 18 |
-
"AI assistant powered by
|
| 19 |
"Try commands like: 'Open Chrome', 'Take a screenshot', 'Create a file', or 'What is AI?'\n"
|
| 20 |
-
"
|
|
|
|
| 21 |
),
|
| 22 |
flagging_mode="never"
|
| 23 |
)
|
|
|
|
| 5 |
# Load model pipeline
|
| 6 |
pipe = load_model()
|
| 7 |
|
| 8 |
+
# Wrapper to handle dynamic output length
|
| 9 |
+
def smart_response(command, execute):
|
| 10 |
+
# Dynamically adjust max_new_tokens based on complexity
|
| 11 |
+
simple_keywords = ["open", "close", "shutdown", "restart", "lock", "screenshot"]
|
| 12 |
+
is_simple = any(keyword in command.lower() for keyword in simple_keywords)
|
| 13 |
+
max_tokens = 128 if is_simple else 1024 # fast for simple, detailed for complex
|
| 14 |
+
|
| 15 |
+
return get_assistant_response(pipe, command, execute, max_new_tokens=max_tokens)
|
| 16 |
+
|
| 17 |
# Gradio UI
|
| 18 |
demo = gr.Interface(
|
| 19 |
+
fn=smart_response,
|
| 20 |
inputs=[
|
| 21 |
gr.Textbox(lines=2, placeholder="e.g. Open Chrome or Take a screenshot", label="🧾 Command"),
|
| 22 |
gr.Checkbox(label="🛠️ Execute command (if possible)")
|
|
|
|
| 24 |
outputs="text",
|
| 25 |
title="🧠 Smart AI Assistant",
|
| 26 |
description=(
|
| 27 |
+
"AI assistant powered by google/medgemma-4b-it\n\n"
|
| 28 |
"Try commands like: 'Open Chrome', 'Take a screenshot', 'Create a file', or 'What is AI?'\n"
|
| 29 |
+
"✔️ Short commands = fast responses | 🧠 Big questions = detailed answers\n"
|
| 30 |
+
"✅ Enable the checkbox to let it run real OS commands (where allowed)"
|
| 31 |
),
|
| 32 |
flagging_mode="never"
|
| 33 |
)
|