aedupuga commited on
Commit
212848e
·
verified ·
1 Parent(s): adf583d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -122
app.py CHANGED
@@ -532,128 +532,37 @@ with st.sidebar:
532
  ''')
533
  add_vertical_space(3)
534
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
 
 
536
 
537
 
538
- # --- CSS FIXES: SIDEBAR WIDER + CHAT TEXT MUCH BIGGER ---
539
- st.markdown("""
540
- <style>
541
-
542
- /* --- MAIN CONTAINER FULL WIDTH --- */
543
- [data-testid="stAppViewContainer"] {
544
- max-width: 100% !important;
545
- padding-left: 10px !important;
546
- padding-right: 40px !important;
547
- }
548
-
549
- /* --- SIDEBAR WIDTH + SMALLER SIDEBAR TEXT --- */
550
- section[data-testid="stSidebar"] {
551
- width: 1.6 vw !important;
552
- }
553
-
554
- section[data-testid="stSidebar"] * {
555
- font-size: .8 vw !important;
556
- }
557
-
558
- /* --- TITLES (untouched) --- */
559
-
560
- /* --- MASSIVE CHAT BUBBLES --- */
561
- div[data-testid="chat-message"] {
562
- font-size: 5 vw !important; /* HUGE readable text */
563
- line-height: 2!important;
564
- padding: 2vw 2.5vw !important; /* large padding */
565
- border-radius: 2vw !important;
566
- max-width: 70% !important;
567
- }
568
-
569
- /* USER MESSAGE */
570
- div[data-testid="chat-message-user"] {
571
- margin-left: auto !important;
572
- background: #00796b !important;
573
- color: white !important;
574
- }
575
-
576
- /* ASSISTANT MESSAGE */
577
- div[data-testid="chat-message-assistant"] {
578
- margin-right: auto !important;
579
- background: #222 !important;
580
- color: white !important;
581
- }
582
-
583
- /* --- INPUT BOX --- */
584
- .stTextInput textarea {
585
- font-size: 2 vw !important;
586
- padding: 1.4vw !important;
587
- min-height: 8vh !important;
588
- border-radius: 1.5vw !important;
589
- }
590
-
591
- /* --- SEND BUTTON --- */
592
- .stButton > button {
593
- font-size: 2 vw !important;
594
- padding: 1vw 2vw !important;
595
- border-radius: 1.5vw !important;
596
- }
597
-
598
-
599
- #--SCALE---
600
-
601
- /* Global scale to simulate 120% zoom */
602
- html {
603
- transform: scale(1.2);
604
- transform-origin: top center;
605
- }
606
-
607
- /* Prevent horizontal scrollbar after scaling */
608
- body, .stApp {
609
- width: 83.33%; /* 1 / 1.2 */
610
- margin: 0 auto;
611
- }
612
-
613
- </style>
614
- """, unsafe_allow_html=True)
615
-
616
-
617
- # --- Centered main title ---
618
-
619
- st.markdown("<h1 class='main-title' style='text-align:center;'>TechSpark AI Assistant</h1>", unsafe_allow_html=True)
620
- st.markdown("<h2 class='sub-title' style='text-align:center;'>Ask me anything about TechSpark — </h2>", unsafe_allow_html=True)
621
-
622
-
623
- # --- Initialize chat history ---
624
- if 'generated' not in st.session_state:
625
- st.session_state['generated'] = ["Hi! I'm your AI assistant. How can I help you today?"]
626
- if 'past' not in st.session_state:
627
- st.session_state['past'] = ["Hi!"]
628
-
629
- # --- Layout containers ---
630
- input_container = st.container()
631
- colored_header(label='', description='', color_name='blue-30')
632
- response_container = st.container()
633
-
634
- # --- User input ---
635
- def get_text():
636
- input_text = st.text_input("You:", "", key="input", placeholder="Type your message here...")
637
- return input_text
638
-
639
- with input_container:
640
- user_input = get_text()
641
-
642
- # --- Generate AI response ---
643
- def generate_response(prompt):
644
- try:
645
- return str(agent.run(prompt))
646
- except Exception as e:
647
- return f"[Error] {e}"
648
-
649
- # --- Display responses ---
650
- with response_container:
651
- if user_input:
652
- response = generate_response(user_input)
653
- st.session_state.past.append(user_input)
654
- st.session_state.generated.append(response)
655
-
656
- if st.session_state['generated']:
657
- for i in range(len(st.session_state['generated'])):
658
- message(st.session_state['past'][i], is_user=True, key=f"{i}_user")
659
- message(st.session_state['generated'][i], key=f"{i}_assistant")
 
532
  ''')
533
  add_vertical_space(3)
534
 
535
+ import gradio as gr
536
+
537
+ # Minimal Gradio chat
538
+ with gr.Blocks(title="TechSpark Agent") as demo:
539
+ gr.Markdown("## Beam Agent — Custom Tool Selection (smolagents + llama.cpp)")
540
+ chat = gr.Chatbot(height=420)
541
+ inp = gr.Textbox(placeholder="Ask your question in natural language.", label="Your question")
542
+
543
+ # No gr.State for agent — just close over `agent`
544
+ def respond(message, history):
545
+ try:
546
+ # 1. Use agent.chat() to maintain internal history
547
+ out = str(agent.run(message))
548
+ except Exception as e:
549
+ out = f"[Error] {e}"
550
+
551
+ # This just updates the Gradio UI history
552
+ history = (history or []) + [(message, out)]
553
+ return "", history
554
+
555
+ gr.Examples(
556
+ fn=respond,
557
+ examples=[
558
+ "Who is Ed?",
559
+ "Who to talk to to create a wooden table?",
560
+ "how to access laser cutter"
561
+ ],
562
+ inputs=[inp]
563
+ )
564
 
565
+ inp.submit(respond, [inp, chat], [inp, chat])
566
 
567
 
568
+ demo.launch(debug=True)