Spaces:
Running
Running
show defaults
Browse files- anycoder_app/ui.py +43 -12
anycoder_app/ui.py
CHANGED
|
@@ -89,6 +89,8 @@ with gr.Blocks(
|
|
| 89 |
current_model = gr.State(DEFAULT_MODEL)
|
| 90 |
open_panel = gr.State(None)
|
| 91 |
last_login_state = gr.State(None)
|
|
|
|
|
|
|
| 92 |
|
| 93 |
with gr.Sidebar() as sidebar:
|
| 94 |
login_button = gr.LoginButton()
|
|
@@ -1775,7 +1777,9 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1775 |
models = get_trending_models(limit=10)
|
| 1776 |
# Create choices list with display names and values as model IDs
|
| 1777 |
choices = [(display, model_id) for display, model_id in models]
|
| 1778 |
-
|
|
|
|
|
|
|
| 1779 |
|
| 1780 |
demo.load(
|
| 1781 |
load_trending_models,
|
|
@@ -1790,7 +1794,9 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1790 |
spaces = get_trending_spaces(limit=10)
|
| 1791 |
# Create choices list with display names and values as space IDs
|
| 1792 |
choices = [(display, space_id) for display, space_id in spaces]
|
| 1793 |
-
|
|
|
|
|
|
|
| 1794 |
|
| 1795 |
demo.load(
|
| 1796 |
load_trending_spaces,
|
|
@@ -1800,8 +1806,20 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1800 |
)
|
| 1801 |
|
| 1802 |
# Handle trending model selection
|
| 1803 |
-
def handle_trending_model_selection(model_id, hist):
|
| 1804 |
"""Handle when user selects a trending model"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1805 |
if not model_id or model_id == "":
|
| 1806 |
return [
|
| 1807 |
gr.update(value="Please select a model.", visible=True), # status
|
|
@@ -1810,7 +1828,7 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1810 |
hist, # history
|
| 1811 |
history_to_chatbot_messages(hist), # history_output
|
| 1812 |
history_to_chatbot_messages(hist), # chat_history
|
| 1813 |
-
|
| 1814 |
]
|
| 1815 |
|
| 1816 |
# Import the model
|
|
@@ -1829,12 +1847,12 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1829 |
loaded_history, # history
|
| 1830 |
history_to_chatbot_messages(loaded_history), # history_output
|
| 1831 |
history_to_chatbot_messages(loaded_history), # chat_history
|
| 1832 |
-
|
| 1833 |
]
|
| 1834 |
|
| 1835 |
trending_models_dropdown.change(
|
| 1836 |
handle_trending_model_selection,
|
| 1837 |
-
inputs=[trending_models_dropdown, history],
|
| 1838 |
outputs=[
|
| 1839 |
trending_models_status,
|
| 1840 |
code_output,
|
|
@@ -1842,13 +1860,26 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1842 |
history,
|
| 1843 |
history_output,
|
| 1844 |
chat_history,
|
| 1845 |
-
|
| 1846 |
]
|
| 1847 |
)
|
| 1848 |
|
| 1849 |
# Handle trending space selection
|
| 1850 |
-
def handle_trending_space_selection(space_id, hist):
|
| 1851 |
"""Handle when user selects a trending space"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1852 |
if not space_id or space_id == "":
|
| 1853 |
return [
|
| 1854 |
gr.update(value="Please select a space.", visible=True), # status
|
|
@@ -1858,7 +1889,7 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1858 |
history_to_chatbot_messages(hist), # history_output
|
| 1859 |
history_to_chatbot_messages(hist), # chat_history
|
| 1860 |
gr.update(visible=True), # deploy_btn
|
| 1861 |
-
|
| 1862 |
]
|
| 1863 |
|
| 1864 |
# Import the space
|
|
@@ -1883,12 +1914,12 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1883 |
history_to_chatbot_messages(loaded_history), # history_output
|
| 1884 |
history_to_chatbot_messages(loaded_history), # chat_history
|
| 1885 |
gr.update(value="Publish", visible=True), # deploy_btn
|
| 1886 |
-
|
| 1887 |
]
|
| 1888 |
|
| 1889 |
trending_spaces_dropdown.change(
|
| 1890 |
handle_trending_space_selection,
|
| 1891 |
-
inputs=[trending_spaces_dropdown, history],
|
| 1892 |
outputs=[
|
| 1893 |
trending_spaces_status,
|
| 1894 |
code_output,
|
|
@@ -1897,7 +1928,7 @@ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.add
|
|
| 1897 |
history_output,
|
| 1898 |
chat_history,
|
| 1899 |
deploy_btn,
|
| 1900 |
-
|
| 1901 |
]
|
| 1902 |
)
|
| 1903 |
|
|
|
|
| 89 |
current_model = gr.State(DEFAULT_MODEL)
|
| 90 |
open_panel = gr.State(None)
|
| 91 |
last_login_state = gr.State(None)
|
| 92 |
+
models_first_change = gr.State(True)
|
| 93 |
+
spaces_first_change = gr.State(True)
|
| 94 |
|
| 95 |
with gr.Sidebar() as sidebar:
|
| 96 |
login_button = gr.LoginButton()
|
|
|
|
| 1777 |
models = get_trending_models(limit=10)
|
| 1778 |
# Create choices list with display names and values as model IDs
|
| 1779 |
choices = [(display, model_id) for display, model_id in models]
|
| 1780 |
+
# Set first model as default value if available
|
| 1781 |
+
default_value = models[0][1] if models and len(models) > 0 and models[0][1] != "" else None
|
| 1782 |
+
return gr.update(choices=choices, value=default_value)
|
| 1783 |
|
| 1784 |
demo.load(
|
| 1785 |
load_trending_models,
|
|
|
|
| 1794 |
spaces = get_trending_spaces(limit=10)
|
| 1795 |
# Create choices list with display names and values as space IDs
|
| 1796 |
choices = [(display, space_id) for display, space_id in spaces]
|
| 1797 |
+
# Set first space as default value if available
|
| 1798 |
+
default_value = spaces[0][1] if spaces and len(spaces) > 0 and spaces[0][1] != "" else None
|
| 1799 |
+
return gr.update(choices=choices, value=default_value)
|
| 1800 |
|
| 1801 |
demo.load(
|
| 1802 |
load_trending_spaces,
|
|
|
|
| 1806 |
)
|
| 1807 |
|
| 1808 |
# Handle trending model selection
|
| 1809 |
+
def handle_trending_model_selection(model_id, hist, is_first):
|
| 1810 |
"""Handle when user selects a trending model"""
|
| 1811 |
+
# Skip import on first change (when default value is set on load)
|
| 1812 |
+
if is_first:
|
| 1813 |
+
return [
|
| 1814 |
+
gr.update(), # status
|
| 1815 |
+
gr.update(), # code_output
|
| 1816 |
+
gr.update(), # language_dropdown
|
| 1817 |
+
hist, # history
|
| 1818 |
+
history_to_chatbot_messages(hist), # history_output
|
| 1819 |
+
history_to_chatbot_messages(hist), # chat_history
|
| 1820 |
+
False # Set first_change to False after first trigger
|
| 1821 |
+
]
|
| 1822 |
+
|
| 1823 |
if not model_id or model_id == "":
|
| 1824 |
return [
|
| 1825 |
gr.update(value="Please select a model.", visible=True), # status
|
|
|
|
| 1828 |
hist, # history
|
| 1829 |
history_to_chatbot_messages(hist), # history_output
|
| 1830 |
history_to_chatbot_messages(hist), # chat_history
|
| 1831 |
+
False # Keep first_change as False
|
| 1832 |
]
|
| 1833 |
|
| 1834 |
# Import the model
|
|
|
|
| 1847 |
loaded_history, # history
|
| 1848 |
history_to_chatbot_messages(loaded_history), # history_output
|
| 1849 |
history_to_chatbot_messages(loaded_history), # chat_history
|
| 1850 |
+
False # Keep first_change as False
|
| 1851 |
]
|
| 1852 |
|
| 1853 |
trending_models_dropdown.change(
|
| 1854 |
handle_trending_model_selection,
|
| 1855 |
+
inputs=[trending_models_dropdown, history, models_first_change],
|
| 1856 |
outputs=[
|
| 1857 |
trending_models_status,
|
| 1858 |
code_output,
|
|
|
|
| 1860 |
history,
|
| 1861 |
history_output,
|
| 1862 |
chat_history,
|
| 1863 |
+
models_first_change
|
| 1864 |
]
|
| 1865 |
)
|
| 1866 |
|
| 1867 |
# Handle trending space selection
|
| 1868 |
+
def handle_trending_space_selection(space_id, hist, is_first):
|
| 1869 |
"""Handle when user selects a trending space"""
|
| 1870 |
+
# Skip import on first change (when default value is set on load)
|
| 1871 |
+
if is_first:
|
| 1872 |
+
return [
|
| 1873 |
+
gr.update(), # status
|
| 1874 |
+
gr.update(), # code_output
|
| 1875 |
+
gr.update(), # language_dropdown
|
| 1876 |
+
hist, # history
|
| 1877 |
+
history_to_chatbot_messages(hist), # history_output
|
| 1878 |
+
history_to_chatbot_messages(hist), # chat_history
|
| 1879 |
+
gr.update(), # deploy_btn
|
| 1880 |
+
False # Set first_change to False after first trigger
|
| 1881 |
+
]
|
| 1882 |
+
|
| 1883 |
if not space_id or space_id == "":
|
| 1884 |
return [
|
| 1885 |
gr.update(value="Please select a space.", visible=True), # status
|
|
|
|
| 1889 |
history_to_chatbot_messages(hist), # history_output
|
| 1890 |
history_to_chatbot_messages(hist), # chat_history
|
| 1891 |
gr.update(visible=True), # deploy_btn
|
| 1892 |
+
False # Keep first_change as False
|
| 1893 |
]
|
| 1894 |
|
| 1895 |
# Import the space
|
|
|
|
| 1914 |
history_to_chatbot_messages(loaded_history), # history_output
|
| 1915 |
history_to_chatbot_messages(loaded_history), # chat_history
|
| 1916 |
gr.update(value="Publish", visible=True), # deploy_btn
|
| 1917 |
+
False # Keep first_change as False
|
| 1918 |
]
|
| 1919 |
|
| 1920 |
trending_spaces_dropdown.change(
|
| 1921 |
handle_trending_space_selection,
|
| 1922 |
+
inputs=[trending_spaces_dropdown, history, spaces_first_change],
|
| 1923 |
outputs=[
|
| 1924 |
trending_spaces_status,
|
| 1925 |
code_output,
|
|
|
|
| 1928 |
history_output,
|
| 1929 |
chat_history,
|
| 1930 |
deploy_btn,
|
| 1931 |
+
spaces_first_change
|
| 1932 |
]
|
| 1933 |
)
|
| 1934 |
|