akhaliq HF Staff commited on
Commit
4f7c59c
Β·
1 Parent(s): 51fb7e5

add chatbot and mobile link

Browse files
Files changed (2) hide show
  1. anycoder_app/parsers.py +1 -1
  2. anycoder_app/ui.py +56 -9
anycoder_app/parsers.py CHANGED
@@ -583,7 +583,7 @@ def history_render(history: History):
583
  return gr.update(visible=True), history
584
 
585
  def clear_history():
586
- return [], [] # Empty lists for both history and chatbot messages
587
 
588
  def create_multimodal_message(text, image=None):
589
  """Create a chat message. For broad provider compatibility, always return content as a string.
 
583
  return gr.update(visible=True), history
584
 
585
  def clear_history():
586
+ return [], [], [] # Empty lists for history, history_output, and chat_history
587
 
588
  def create_multimodal_message(text, image=None):
589
  """Create a chat message. For broad provider compatibility, always return content as a string.
anycoder_app/ui.py CHANGED
@@ -69,6 +69,16 @@ with gr.Blocks(
69
  border: 1px solid rgba(46, 204, 113, 0.3);
70
  color: #2ecc71;
71
  }
 
 
 
 
 
 
 
 
 
 
72
  """
73
  ) as demo:
74
  history = gr.State([])
@@ -82,7 +92,18 @@ with gr.Blocks(
82
  with gr.Sidebar() as sidebar:
83
  login_button = gr.LoginButton()
84
 
85
-
 
 
 
 
 
 
 
 
 
 
 
86
 
87
 
88
  # Unified Import section
@@ -95,10 +116,20 @@ with gr.Blocks(
95
  load_project_btn = gr.Button("πŸ“₯ Import Project", variant="secondary", size="sm", visible=True)
96
  load_project_status = gr.Markdown(visible=False)
97
 
 
 
 
 
 
 
 
 
 
 
98
  input = gr.Textbox(
99
  label="What would you like to build?",
100
  placeholder="πŸ”’ Please log in with Hugging Face to use AnyCoder...",
101
- lines=3,
102
  visible=True,
103
  interactive=False
104
  )
@@ -295,7 +326,8 @@ with gr.Blocks(
295
  gr.update(value="Publish", visible=False),
296
  gr.update(), # keep import header as-is
297
  gr.update(), # keep import button as-is
298
- gr.update() # language dropdown - no change
 
299
  ]
300
 
301
  kind, meta = _parse_repo_or_model_url(url)
@@ -337,7 +369,8 @@ with gr.Blocks(
337
  gr.update(value="Publish", visible=True),
338
  gr.update(visible=False), # hide import header
339
  gr.update(visible=False), # hide import button
340
- gr.update(value=framework_type) # set language dropdown to framework type
 
341
  ]
342
  else:
343
  # GitHub or HF model β†’ return raw snippet for LLM starting point
@@ -361,7 +394,8 @@ with gr.Blocks(
361
  gr.update(value="Publish", visible=False),
362
  gr.update(visible=False), # hide import header
363
  gr.update(visible=False), # hide import button
364
- gr.update(value=framework_type) # set language dropdown to detected language
 
365
  ]
366
 
367
  # Import repo/model handler
@@ -796,6 +830,7 @@ with gr.Blocks(
796
  import_header_md,
797
  load_project_btn,
798
  language_dropdown,
 
799
  ],
800
  )
801
 
@@ -813,7 +848,15 @@ with gr.Blocks(
813
 
814
  def generation_code_wrapper(inp, sett, hist, model, lang, prov, profile: Optional[gr.OAuthProfile] = None, token: Optional[gr.OAuthToken] = None):
815
  """Wrapper to call generation_code and pass component references"""
816
- yield from generation_code(inp, sett, hist, model, lang, prov, profile, token, code_output, history_output, history)
 
 
 
 
 
 
 
 
817
 
818
  btn.click(
819
  begin_generation_ui,
@@ -823,7 +866,7 @@ with gr.Blocks(
823
  ).then(
824
  generation_code_wrapper,
825
  inputs=[input, setting, history, current_model, language_dropdown, provider_state],
826
- outputs=[code_output, history, history_output]
827
  ).then(
828
  end_generation_ui,
829
  inputs=None,
@@ -871,7 +914,7 @@ with gr.Blocks(
871
  ).then(
872
  generation_code_wrapper,
873
  inputs=[input, setting, history, current_model, language_dropdown, provider_state],
874
- outputs=[code_output, history, history_output]
875
  ).then(
876
  end_generation_ui,
877
  inputs=None,
@@ -935,7 +978,7 @@ with gr.Blocks(
935
  </div>
936
  """
937
 
938
- clear_btn.click(clear_history, outputs=[history, history_output])
939
  clear_btn.click(hide_deploy_components, None, [deploy_btn])
940
  # Reset button text when clearing
941
  clear_btn.click(
@@ -1676,6 +1719,10 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
1676
  deploy_with_history_tracking,
1677
  inputs=[code_output, language_dropdown, history],
1678
  outputs=[deploy_status, history]
 
 
 
 
1679
  )
1680
  # Keep the old deploy method as fallback (if not logged in, user can still use the old method)
1681
  # Optionally, you can keep the old deploy_btn.click for the default method as a secondary button.
 
69
  border: 1px solid rgba(46, 204, 113, 0.3);
70
  color: #2ecc71;
71
  }
72
+ /* App link styling (visible on all devices) */
73
+ .app-link {
74
+ display: block;
75
+ padding: 12px;
76
+ border-radius: 8px;
77
+ background: rgba(59, 130, 246, 0.1);
78
+ border: 1px solid rgba(59, 130, 246, 0.3);
79
+ margin: 12px 0;
80
+ text-align: center;
81
+ }
82
  """
83
  ) as demo:
84
  history = gr.State([])
 
92
  with gr.Sidebar() as sidebar:
93
  login_button = gr.LoginButton()
94
 
95
+ # App link (visible on all devices)
96
+ mobile_link = gr.Markdown(
97
+ """
98
+ <div class="app-link">
99
+ πŸ“± <strong>Using Mobile?</strong><br/>
100
+ <a href="https://akhaliq-anycoder.hf.space" target="_blank" style="color: #007bff; text-decoration: underline;">
101
+ Use the app here
102
+ </a>
103
+ </div>
104
+ """,
105
+ visible=True
106
+ )
107
 
108
 
109
  # Unified Import section
 
116
  load_project_btn = gr.Button("πŸ“₯ Import Project", variant="secondary", size="sm", visible=True)
117
  load_project_status = gr.Markdown(visible=False)
118
 
119
+ # Chat history display in sidebar
120
+ chat_history = gr.Chatbot(
121
+ label="Conversation History",
122
+ type="messages",
123
+ height=300,
124
+ show_copy_button=True,
125
+ visible=True
126
+ )
127
+
128
+ # Input textbox for new messages
129
  input = gr.Textbox(
130
  label="What would you like to build?",
131
  placeholder="πŸ”’ Please log in with Hugging Face to use AnyCoder...",
132
+ lines=2,
133
  visible=True,
134
  interactive=False
135
  )
 
326
  gr.update(value="Publish", visible=False),
327
  gr.update(), # keep import header as-is
328
  gr.update(), # keep import button as-is
329
+ gr.update(), # language dropdown - no change
330
+ [] # chat_history
331
  ]
332
 
333
  kind, meta = _parse_repo_or_model_url(url)
 
369
  gr.update(value="Publish", visible=True),
370
  gr.update(visible=False), # hide import header
371
  gr.update(visible=False), # hide import button
372
+ gr.update(value=framework_type), # set language dropdown to framework type
373
+ history_to_chatbot_messages(loaded_history) # chat_history
374
  ]
375
  else:
376
  # GitHub or HF model β†’ return raw snippet for LLM starting point
 
394
  gr.update(value="Publish", visible=False),
395
  gr.update(visible=False), # hide import header
396
  gr.update(visible=False), # hide import button
397
+ gr.update(value=framework_type), # set language dropdown to detected language
398
+ history_to_chatbot_messages(loaded_history) # chat_history
399
  ]
400
 
401
  # Import repo/model handler
 
830
  import_header_md,
831
  load_project_btn,
832
  language_dropdown,
833
+ chat_history, # Add chat_history to outputs
834
  ],
835
  )
836
 
 
848
 
849
  def generation_code_wrapper(inp, sett, hist, model, lang, prov, profile: Optional[gr.OAuthProfile] = None, token: Optional[gr.OAuthToken] = None):
850
  """Wrapper to call generation_code and pass component references"""
851
+ # Generate code and update both history and chat_history
852
+ for result in generation_code(inp, sett, hist, model, lang, prov, profile, token, code_output, history_output, history):
853
+ # generation_code yields dictionaries with component keys
854
+ # Extract the values and yield them for our outputs
855
+ code_val = result.get(code_output, "")
856
+ hist_val = result.get(history, hist)
857
+ history_output_val = result.get(history_output, [])
858
+ # Yield for: code_output, history, history_output, chat_history
859
+ yield code_val, hist_val, history_output_val, history_output_val
860
 
861
  btn.click(
862
  begin_generation_ui,
 
866
  ).then(
867
  generation_code_wrapper,
868
  inputs=[input, setting, history, current_model, language_dropdown, provider_state],
869
+ outputs=[code_output, history, history_output, chat_history]
870
  ).then(
871
  end_generation_ui,
872
  inputs=None,
 
914
  ).then(
915
  generation_code_wrapper,
916
  inputs=[input, setting, history, current_model, language_dropdown, provider_state],
917
+ outputs=[code_output, history, history_output, chat_history]
918
  ).then(
919
  end_generation_ui,
920
  inputs=None,
 
978
  </div>
979
  """
980
 
981
+ clear_btn.click(clear_history, outputs=[history, history_output, chat_history])
982
  clear_btn.click(hide_deploy_components, None, [deploy_btn])
983
  # Reset button text when clearing
984
  clear_btn.click(
 
1719
  deploy_with_history_tracking,
1720
  inputs=[code_output, language_dropdown, history],
1721
  outputs=[deploy_status, history]
1722
+ ).then(
1723
+ lambda hist: history_to_chatbot_messages(hist),
1724
+ inputs=[history],
1725
+ outputs=[chat_history]
1726
  )
1727
  # Keep the old deploy method as fallback (if not logged in, user can still use the old method)
1728
  # Optionally, you can keep the old deploy_btn.click for the default method as a secondary button.