Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -516,22 +516,8 @@ agent = smolagents.CodeAgent(
|
|
| 516 |
verbosity_level=2, # show steps in logs for class demo
|
| 517 |
)
|
| 518 |
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
# --- Sidebar ---
|
| 523 |
-
with st.sidebar:
|
| 524 |
-
st.markdown("<h1 style='text-align:center; font-size:2.5em;'>❇️ TechSpark AI Assistant</h1>", unsafe_allow_html=True)
|
| 525 |
-
st.markdown('''
|
| 526 |
-
## About
|
| 527 |
-
This app is a tech-powered AI chatbot built using:
|
| 528 |
-
- Streamlit
|
| 529 |
-
- smolagents for AI responses
|
| 530 |
-
|
| 531 |
-
️ No API key required!
|
| 532 |
-
''')
|
| 533 |
-
add_vertical_space(3)
|
| 534 |
-
|
| 535 |
import gradio as gr
|
| 536 |
|
| 537 |
# Minimal Gradio chat
|
|
@@ -563,6 +549,149 @@ with gr.Blocks(title="TechSpark Agent") as demo:
|
|
| 563 |
)
|
| 564 |
|
| 565 |
inp.submit(respond, [inp, chat], [inp, chat])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
|
| 567 |
|
| 568 |
demo.launch(debug=True)
|
|
|
|
| 516 |
verbosity_level=2, # show steps in logs for class demo
|
| 517 |
)
|
| 518 |
|
| 519 |
+
"""
|
| 520 |
+
# --- Sidebar --
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
import gradio as gr
|
| 522 |
|
| 523 |
# Minimal Gradio chat
|
|
|
|
| 549 |
)
|
| 550 |
|
| 551 |
inp.submit(respond, [inp, chat], [inp, chat])
|
| 552 |
+
"""
|
| 553 |
+
|
| 554 |
+
# --- Page config ---
|
| 555 |
+
st.set_page_config(page_title="TechSpark AI Assistant", layout="wide")
|
| 556 |
+
|
| 557 |
+
# --- Sidebar ---
|
| 558 |
+
with st.sidebar:
|
| 559 |
+
st.markdown("<h1 style='text-align:center; font-size:2.5em;'>🤖 TechSpark AI Assistant</h1>", unsafe_allow_html=True)
|
| 560 |
+
st.markdown('''
|
| 561 |
+
## About
|
| 562 |
+
This app is a tech-powered AI chatbot built using:
|
| 563 |
+
- Streamlit
|
| 564 |
+
- smolagents for AI responses
|
| 565 |
+
|
| 566 |
+
💡 No API key required!
|
| 567 |
+
''')
|
| 568 |
+
add_vertical_space(3)
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
# --- CSS FIXES: SIDEBAR WIDER + CHAT TEXT MUCH BIGGER ---
|
| 574 |
+
st.markdown("""
|
| 575 |
+
<style>
|
| 576 |
+
|
| 577 |
+
/* --- MAIN CONTAINER FULL WIDTH --- */
|
| 578 |
+
[data-testid="stAppViewContainer"] {
|
| 579 |
+
max-width: 100% !important;
|
| 580 |
+
padding-left: 10px !important;
|
| 581 |
+
padding-right: 40px !important;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
/* --- SIDEBAR WIDTH + SMALLER SIDEBAR TEXT --- */
|
| 585 |
+
section[data-testid="stSidebar"] {
|
| 586 |
+
width: 1.6 vw !important;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
section[data-testid="stSidebar"] * {
|
| 590 |
+
font-size: .8 vw !important;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
/* --- TITLES (untouched) --- */
|
| 594 |
+
|
| 595 |
+
/* --- MASSIVE CHAT BUBBLES --- */
|
| 596 |
+
div[data-testid="chat-message"] {
|
| 597 |
+
font-size: 5 vw !important; /* HUGE readable text */
|
| 598 |
+
line-height: 2!important;
|
| 599 |
+
padding: 2vw 2.5vw !important; /* large padding */
|
| 600 |
+
border-radius: 2vw !important;
|
| 601 |
+
max-width: 70% !important;
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
/* USER MESSAGE */
|
| 605 |
+
div[data-testid="chat-message-user"] {
|
| 606 |
+
margin-left: auto !important;
|
| 607 |
+
background: #00796b !important;
|
| 608 |
+
color: white !important;
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
/* ASSISTANT MESSAGE */
|
| 612 |
+
div[data-testid="chat-message-assistant"] {
|
| 613 |
+
margin-right: auto !important;
|
| 614 |
+
background: #222 !important;
|
| 615 |
+
color: white !important;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
/* --- INPUT BOX --- */
|
| 619 |
+
.stTextInput textarea {
|
| 620 |
+
font-size: 2 vw !important;
|
| 621 |
+
padding: 1.4vw !important;
|
| 622 |
+
min-height: 8vh !important;
|
| 623 |
+
border-radius: 1.5vw !important;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
/* --- SEND BUTTON --- */
|
| 627 |
+
.stButton > button {
|
| 628 |
+
font-size: 2 vw !important;
|
| 629 |
+
padding: 1vw 2vw !important;
|
| 630 |
+
border-radius: 1.5vw !important;
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
#--SCALE---
|
| 635 |
+
|
| 636 |
+
/* Global scale to simulate 120% zoom */
|
| 637 |
+
html {
|
| 638 |
+
transform: scale(1.2);
|
| 639 |
+
transform-origin: top center;
|
| 640 |
+
}
|
| 641 |
+
|
| 642 |
+
/* Prevent horizontal scrollbar after scaling */
|
| 643 |
+
body, .stApp {
|
| 644 |
+
width: 83.33%; /* 1 / 1.2 */
|
| 645 |
+
margin: 0 auto;
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
</style>
|
| 649 |
+
""", unsafe_allow_html=True)
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
# --- Centered main title ---
|
| 653 |
+
|
| 654 |
+
st.markdown("<h1 class='main-title' style='text-align:center;'>TechSpark AI Assistant</h1>", unsafe_allow_html=True)
|
| 655 |
+
st.markdown("<h2 class='sub-title' style='text-align:center;'>Ask me anything about TechSpark — </h2>", unsafe_allow_html=True)
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
# --- Initialize chat history ---
|
| 659 |
+
if 'generated' not in st.session_state:
|
| 660 |
+
st.session_state['generated'] = ["Hi! I'm your AI assistant. How can I help you today?"]
|
| 661 |
+
if 'past' not in st.session_state:
|
| 662 |
+
st.session_state['past'] = ["Hi!"]
|
| 663 |
+
|
| 664 |
+
# --- Layout containers ---
|
| 665 |
+
input_container = st.container()
|
| 666 |
+
colored_header(label='', description='', color_name='blue-30')
|
| 667 |
+
response_container = st.container()
|
| 668 |
+
|
| 669 |
+
# --- User input ---
|
| 670 |
+
def get_text():
|
| 671 |
+
input_text = st.text_input("You:", "", key="input", placeholder="Type your message here...")
|
| 672 |
+
return input_text
|
| 673 |
+
|
| 674 |
+
with input_container:
|
| 675 |
+
user_input = get_text()
|
| 676 |
+
|
| 677 |
+
# --- Generate AI response ---
|
| 678 |
+
def generate_response(prompt):
|
| 679 |
+
try:
|
| 680 |
+
return str(smolagents.agent(prompt))
|
| 681 |
+
except Exception as e:
|
| 682 |
+
return f"[Error] {e}"
|
| 683 |
+
|
| 684 |
+
# --- Display responses ---
|
| 685 |
+
with response_container:
|
| 686 |
+
if user_input:
|
| 687 |
+
response = generate_response(user_input)
|
| 688 |
+
st.session_state.past.append(user_input)
|
| 689 |
+
st.session_state.generated.append(response)
|
| 690 |
+
|
| 691 |
+
if st.session_state['generated']:
|
| 692 |
+
for i in range(len(st.session_state['generated'])):
|
| 693 |
+
message(st.session_state['past'][i], is_user=True, key=f"{i}_user")
|
| 694 |
+
message(st.session_state['generated'][i], key=f"{i}_assistant")
|
| 695 |
|
| 696 |
|
| 697 |
demo.launch(debug=True)
|