Tijmen2 commited on
Commit
9e7d5d4
Β·
verified Β·
1 Parent(s): 96edac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -55,11 +55,12 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
55
  def clear_context():
56
  return [], get_random_greeting()
57
 
 
58
  with gr.Blocks() as demo:
59
- gr.HTML("<div class='header-text'>🌌 AstroSage-LLAMA-3.1-8B</div><div class='subheader'>Your AI Guide to the Cosmos</div>")
60
 
61
  chatbot = gr.Chatbot(height=400)
62
- msg = gr.Textbox(placeholder="Ask about astronomy, astrophysics, or cosmology...")
63
 
64
  with gr.Accordion("Advanced Settings", open=False) as advanced_settings:
65
  system_msg = gr.Textbox(
@@ -71,22 +72,21 @@ with gr.Blocks() as demo:
71
  temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
72
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
73
 
74
- with gr.Row():
75
- clear = gr.Button("🌟 New Chat")
76
- submit = gr.Button("Send πŸš€", variant="primary")
77
-
78
  def handle_submit(message, history, system_message, max_tokens, temperature, top_p):
79
  response = respond(message, history, system_message, max_tokens, temperature, top_p)
80
  history.append((message, response))
81
  return history, ""
82
 
83
- submit.click(
84
  handle_submit,
85
- [msg, chatbot, system_msg, max_tokens, temperature, top_p],
86
- [chatbot, msg]
 
87
  )
88
 
89
- clear.click(clear_context, [], [chatbot, msg])
 
90
 
91
  if __name__ == "__main__":
92
  demo.launch()
 
55
  def clear_context():
56
  return [], get_random_greeting()
57
 
58
+ # Gradio Interface
59
  with gr.Blocks() as demo:
60
+ gr.HTML("<div class='header-text'>AstroSage-LLAMA-3.1-8B</div><div class='subheader'>Astromony-Specialized Chatbot</div>")
61
 
62
  chatbot = gr.Chatbot(height=400)
63
+ msg = gr.Textbox(placeholder="Ask about astronomy, astrophysics, or cosmology...", show_label=False)
64
 
65
  with gr.Accordion("Advanced Settings", open=False) as advanced_settings:
66
  system_msg = gr.Textbox(
 
72
  temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
73
  top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
74
 
75
+ # Automatically handle submission on Enter key press
 
 
 
76
  def handle_submit(message, history, system_message, max_tokens, temperature, top_p):
77
  response = respond(message, history, system_message, max_tokens, temperature, top_p)
78
  history.append((message, response))
79
  return history, ""
80
 
81
+ msg.submit(
82
  handle_submit,
83
+ inputs=[msg, chatbot, system_msg, max_tokens, temperature, top_p],
84
+ outputs=[chatbot, msg],
85
+ queue=False
86
  )
87
 
88
+ # Automatically clear context on reload
89
+ demo.load(lambda: clear_context(), None, [chatbot, msg])
90
 
91
  if __name__ == "__main__":
92
  demo.launch()