Update app.py
Browse files
app.py
CHANGED
|
@@ -6,26 +6,39 @@ from groq import Groq
|
|
| 6 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 7 |
client = Groq(api_key=api_key)
|
| 8 |
|
| 9 |
-
# 2. UI Styling with
|
| 10 |
custom_css = """
|
| 11 |
.gradio-container { max-height: 100vh !important; overflow: hidden !important; }
|
|
|
|
|
|
|
| 12 |
#chatbot-window {
|
| 13 |
-
height:
|
| 14 |
border-radius: 12px;
|
| 15 |
border: 1px solid #e0e0e0;
|
| 16 |
background: white;
|
| 17 |
}
|
| 18 |
|
| 19 |
-
/*
|
| 20 |
#system-prompt-container textarea {
|
| 21 |
-
|
|
|
|
| 22 |
overflow-y: auto !important;
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
-
/*
|
| 26 |
.scroll-input textarea {
|
| 27 |
-
|
|
|
|
| 28 |
overflow-y: auto !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
"""
|
| 31 |
|
|
@@ -51,16 +64,16 @@ def chat_with_groq(message, history, model, temperature, system_prompt):
|
|
| 51 |
except Exception as e:
|
| 52 |
yield f"⚠️ API Error: {str(e)}"
|
| 53 |
|
| 54 |
-
# 4.
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
-
gr.Markdown("#
|
| 57 |
gr.Markdown("I am your personal assistant. Just input your task below for an instant, precise solution.")
|
| 58 |
|
| 59 |
with gr.Row():
|
|
|
|
| 60 |
with gr.Column(scale=4):
|
| 61 |
chatbot = gr.Chatbot(elem_id="chatbot-window")
|
| 62 |
with gr.Row():
|
| 63 |
-
# ADDED elem_classes here to enable scrolling
|
| 64 |
msg_input = gr.Textbox(
|
| 65 |
placeholder="Ask me anything...",
|
| 66 |
container=False,
|
|
@@ -69,7 +82,8 @@ with gr.Blocks() as demo:
|
|
| 69 |
)
|
| 70 |
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
gr.Markdown("### ⚙️ Settings")
|
| 74 |
model_choice = gr.Dropdown(
|
| 75 |
choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
|
|
@@ -80,13 +94,25 @@ with gr.Blocks() as demo:
|
|
| 80 |
sys_msg = gr.Textbox(
|
| 81 |
value="You are a professional assistant.",
|
| 82 |
label="System Prompt",
|
| 83 |
-
lines=
|
| 84 |
elem_id="system-prompt-container"
|
| 85 |
)
|
| 86 |
clear = gr.Button("Clear Chat", variant="stop")
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# --- UI Event Flow ---
|
| 89 |
def user_turn(msg, hist):
|
|
|
|
| 90 |
hist.append({"role": "user", "content": msg})
|
| 91 |
return "", hist
|
| 92 |
|
|
@@ -98,6 +124,7 @@ with gr.Blocks() as demo:
|
|
| 98 |
hist[-1]["content"] = chunk
|
| 99 |
yield hist
|
| 100 |
|
|
|
|
| 101 |
msg_input.submit(user_turn, [msg_input, chatbot], [msg_input, chatbot], queue=False).then(
|
| 102 |
bot_turn, [chatbot, model_choice, temp, sys_msg], chatbot
|
| 103 |
)
|
|
|
|
| 6 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 7 |
client = Groq(api_key=api_key)
|
| 8 |
|
| 9 |
+
# 2. UI Styling with Single-Line Scroll Fix
|
| 10 |
custom_css = """
|
| 11 |
.gradio-container { max-height: 100vh !important; overflow: hidden !important; }
|
| 12 |
+
|
| 13 |
+
/* Chatbot Panel Styles */
|
| 14 |
#chatbot-window {
|
| 15 |
+
height: 60vh !important;
|
| 16 |
border-radius: 12px;
|
| 17 |
border: 1px solid #e0e0e0;
|
| 18 |
background: white;
|
| 19 |
}
|
| 20 |
|
| 21 |
+
/* Forces System Prompt to scroll after one line */
|
| 22 |
#system-prompt-container textarea {
|
| 23 |
+
height: 45px !important;
|
| 24 |
+
max-height: 45px !important;
|
| 25 |
overflow-y: auto !important;
|
| 26 |
+
resize: none !important;
|
| 27 |
}
|
| 28 |
|
| 29 |
+
/* Forces Chat Input to scroll after one line */
|
| 30 |
.scroll-input textarea {
|
| 31 |
+
height: 45px !important;
|
| 32 |
+
max-height: 45px !important;
|
| 33 |
overflow-y: auto !important;
|
| 34 |
+
resize: none !important;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/* Sidebar Styling */
|
| 38 |
+
.sidebar-panel {
|
| 39 |
+
background-color: rgba(128, 128, 128, 0.05);
|
| 40 |
+
padding: 15px !important;
|
| 41 |
+
border-radius: 12px;
|
| 42 |
}
|
| 43 |
"""
|
| 44 |
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
yield f"⚠️ API Error: {str(e)}"
|
| 66 |
|
| 67 |
+
# 4. Interface Setup
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
+
gr.Markdown("# 🌿 SageBot")
|
| 70 |
gr.Markdown("I am your personal assistant. Just input your task below for an instant, precise solution.")
|
| 71 |
|
| 72 |
with gr.Row():
|
| 73 |
+
# Main Interaction Area
|
| 74 |
with gr.Column(scale=4):
|
| 75 |
chatbot = gr.Chatbot(elem_id="chatbot-window")
|
| 76 |
with gr.Row():
|
|
|
|
| 77 |
msg_input = gr.Textbox(
|
| 78 |
placeholder="Ask me anything...",
|
| 79 |
container=False,
|
|
|
|
| 82 |
)
|
| 83 |
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
| 84 |
|
| 85 |
+
# Sidebar Area
|
| 86 |
+
with gr.Column(scale=1, elem_classes="sidebar-panel"):
|
| 87 |
gr.Markdown("### ⚙️ Settings")
|
| 88 |
model_choice = gr.Dropdown(
|
| 89 |
choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant"],
|
|
|
|
| 94 |
sys_msg = gr.Textbox(
|
| 95 |
value="You are a professional assistant.",
|
| 96 |
label="System Prompt",
|
| 97 |
+
lines=1,
|
| 98 |
elem_id="system-prompt-container"
|
| 99 |
)
|
| 100 |
clear = gr.Button("Clear Chat", variant="stop")
|
| 101 |
|
| 102 |
+
# Integrated LinkedIn Support
|
| 103 |
+
gr.HTML("""
|
| 104 |
+
<div style="text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
|
| 105 |
+
<a href="https://www.linkedin.com/in/YOUR_LINKEDIN_USERNAME" target="_blank" style="text-decoration: none;">
|
| 106 |
+
<svg width="35" height="35" viewBox="0 0 24 24" fill="#0077b5">
|
| 107 |
+
<path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.239-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/>
|
| 108 |
+
</svg>
|
| 109 |
+
</a>
|
| 110 |
+
</div>
|
| 111 |
+
""")
|
| 112 |
+
|
| 113 |
# --- UI Event Flow ---
|
| 114 |
def user_turn(msg, hist):
|
| 115 |
+
if not msg: return "", hist
|
| 116 |
hist.append({"role": "user", "content": msg})
|
| 117 |
return "", hist
|
| 118 |
|
|
|
|
| 124 |
hist[-1]["content"] = chunk
|
| 125 |
yield hist
|
| 126 |
|
| 127 |
+
# Event Linking
|
| 128 |
msg_input.submit(user_turn, [msg_input, chatbot], [msg_input, chatbot], queue=False).then(
|
| 129 |
bot_turn, [chatbot, model_choice, temp, sys_msg], chatbot
|
| 130 |
)
|