Test-Space-07-31-2025-11:49AM
Browse files- app.py +25 -63
- config.json +5 -5
- requirements.txt +2 -1
app.py
CHANGED
@@ -17,12 +17,12 @@ SPACE_DESCRIPTION = 'A customizable AI assistant'
|
|
17 |
DEFAULT_CONFIG = {
|
18 |
'name': SPACE_NAME,
|
19 |
'description': SPACE_DESCRIPTION,
|
20 |
-
'system_prompt': "You are a Socratic conversation partner for students in general education courses across all disciplines with strengths in the pebble-in-the-pond learning model, responsive teaching, and constructivist learning principles. Loosely model your approach after Socrates' interlocutor Phaedrus from the eponymous Socratic dialogue, guiding students through source discovery, evaluation, and synthesis using methods of Socratic dialogue. Ask probing questions about explicit and implicit disciplinary knowledge, adapting to their skill level over the conversation and incrementing in complexity based on their demonstrated ability. Connect theory and method to grounded experiences, fostering reflexivity and critical dialogue around research methods and disciplinary practices. Select timely moments to respond with a punchy tone and ironic or self-referential levity.
|
21 |
-
'temperature': 0.
|
22 |
-
'max_tokens':
|
23 |
-
'model': '
|
24 |
'api_key_var': 'API_KEY',
|
25 |
-
'theme': '
|
26 |
'grounding_urls': '["https://classics.mit.edu/Plato/phaedrus.1b.txt", "https://plato.stanford.edu/entries/plato-rhetoric/#Pha", "https://plato.stanford.edu/entries/plato-myths/", "https://en.wikipedia.org/wiki/Socratic_method", "https://en.wikipedia.org/wiki/Research_methodology", "https://en.wikipedia.org/wiki/Academic_research", "https://www.reddit.com/r/askphilosophy/comments/m6u36v/can_someone_go_over_the_socratic_method_and_give/", "https://www.reddit.com/r/askphilosophy/comments/k5td4z/is_socratic_method_the_best_way_to_change/"]',
|
27 |
'enable_dynamic_urls': True,
|
28 |
'examples': ['Can you help me understand why the sky is blue?', 'What makes democracy different from other forms of government?', 'How does the Socratic method apply to modern education?'],
|
@@ -570,13 +570,13 @@ def get_configuration_status():
|
|
570 |
# Dynamically set theme based on configuration
|
571 |
theme_class = getattr(gr.themes, THEME, gr.themes.Default)
|
572 |
with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
573 |
-
# Check if
|
574 |
-
|
|
|
575 |
|
576 |
-
#
|
577 |
-
|
578 |
-
with gr.
|
579 |
-
with gr.Tab("Chat U/I"):
|
580 |
gr.Markdown(f"# {SPACE_NAME}")
|
581 |
gr.Markdown(SPACE_DESCRIPTION)
|
582 |
|
@@ -648,28 +648,20 @@ with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
|
648 |
outputs=[access_error, chat_section, access_granted]
|
649 |
)
|
650 |
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
gr.Markdown("Edit assistant configuration. Requires authentication.")
|
655 |
-
|
656 |
-
faculty_auth_state = gr.State(False)
|
657 |
-
faculty_auth_state = gr.State(False)
|
658 |
|
659 |
-
#
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
scale=3
|
667 |
-
)
|
668 |
-
faculty_auth_btn = gr.Button("Unlock Configuration", variant="primary", scale=1)
|
669 |
-
faculty_auth_status = gr.Markdown("")
|
670 |
|
671 |
-
# Configuration editor (
|
672 |
-
with gr.Column(visible=
|
673 |
gr.Markdown("### Edit Assistant Configuration")
|
674 |
gr.Markdown("⚠️ **Warning:** Changes will affect all users immediately.")
|
675 |
|
@@ -768,25 +760,9 @@ with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
|
768 |
|
769 |
config_status = gr.Markdown("")
|
770 |
|
771 |
-
# Faculty authentication function
|
772 |
-
def verify_faculty_password(password):
|
773 |
-
if password == FACULTY_PASSWORD:
|
774 |
-
return (
|
775 |
-
gr.update(value="Authentication successful!"),
|
776 |
-
gr.update(visible=False), # Hide auth row
|
777 |
-
gr.update(visible=True), # Show config section
|
778 |
-
True # Update auth state
|
779 |
-
)
|
780 |
-
else:
|
781 |
-
return (
|
782 |
-
gr.update(value="Invalid password"),
|
783 |
-
gr.update(visible=True), # Keep auth row visible
|
784 |
-
gr.update(visible=False), # Keep config hidden
|
785 |
-
False # Auth failed
|
786 |
-
)
|
787 |
|
788 |
# Save configuration function
|
789 |
-
def save_configuration(new_prompt, new_model, new_examples, new_temp, new_tokens, *url_values
|
790 |
if not is_authenticated:
|
791 |
return "Not authenticated"
|
792 |
|
@@ -936,23 +912,11 @@ with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
|
936 |
|
937 |
return tuple(updates)
|
938 |
|
939 |
-
# Connect authentication
|
940 |
-
faculty_auth_btn.click(
|
941 |
-
verify_faculty_password,
|
942 |
-
inputs=[faculty_password_input],
|
943 |
-
outputs=[faculty_auth_status, faculty_auth_row, faculty_config_section, faculty_auth_state]
|
944 |
-
)
|
945 |
-
|
946 |
-
faculty_password_input.submit(
|
947 |
-
verify_faculty_password,
|
948 |
-
inputs=[faculty_password_input],
|
949 |
-
outputs=[faculty_auth_status, faculty_auth_row, faculty_config_section, faculty_auth_state]
|
950 |
-
)
|
951 |
|
952 |
# Connect configuration buttons
|
953 |
save_config_btn.click(
|
954 |
save_configuration,
|
955 |
-
inputs=[edit_system_prompt, edit_model, edit_examples, edit_temperature, edit_max_tokens] + url_fields + [config_locked
|
956 |
outputs=[config_status]
|
957 |
)
|
958 |
|
@@ -961,8 +925,6 @@ with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
|
961 |
inputs=[faculty_auth_state],
|
962 |
outputs=[config_status, edit_system_prompt, edit_model, edit_examples, edit_temperature, edit_max_tokens] + url_fields
|
963 |
)
|
964 |
-
else:
|
965 |
-
gr.Markdown("Faculty configuration is not enabled. Set CONFIG_CODE in Space secrets to enable.")
|
966 |
|
967 |
if __name__ == "__main__":
|
968 |
demo.launch()
|
|
|
17 |
DEFAULT_CONFIG = {
|
18 |
'name': SPACE_NAME,
|
19 |
'description': SPACE_DESCRIPTION,
|
20 |
+
'system_prompt': "You are a Socratic conversation partner for students in general education courses across all disciplines with strengths in the pebble-in-the-pond learning model, responsive teaching, and constructivist learning principles. Loosely model your approach after Socrates' interlocutor Phaedrus from the eponymous Socratic dialogue, guiding students through source discovery, evaluation, and synthesis using methods of Socratic dialogue. Ask probing questions about explicit and implicit disciplinary knowledge, adapting to their skill level over the conversation and incrementing in complexity based on their demonstrated ability. Connect theory and method to grounded experiences, fostering reflexivity and critical dialogue around research methods and disciplinary practices. Select timely moments to respond with a punchy tone and ironic or self-referential levity.",
|
21 |
+
'temperature': 0.7,
|
22 |
+
'max_tokens': 750,
|
23 |
+
'model': 'google/gemini-2.0-flash-001',
|
24 |
'api_key_var': 'API_KEY',
|
25 |
+
'theme': 'Default',
|
26 |
'grounding_urls': '["https://classics.mit.edu/Plato/phaedrus.1b.txt", "https://plato.stanford.edu/entries/plato-rhetoric/#Pha", "https://plato.stanford.edu/entries/plato-myths/", "https://en.wikipedia.org/wiki/Socratic_method", "https://en.wikipedia.org/wiki/Research_methodology", "https://en.wikipedia.org/wiki/Academic_research", "https://www.reddit.com/r/askphilosophy/comments/m6u36v/can_someone_go_over_the_socratic_method_and_give/", "https://www.reddit.com/r/askphilosophy/comments/k5td4z/is_socratic_method_the_best_way_to_change/"]',
|
27 |
'enable_dynamic_urls': True,
|
28 |
'examples': ['Can you help me understand why the sky is blue?', 'What makes democracy different from other forms of government?', 'How does the Socratic method apply to modern education?'],
|
|
|
570 |
# Dynamically set theme based on configuration
|
571 |
theme_class = getattr(gr.themes, THEME, gr.themes.Default)
|
572 |
with gr.Blocks(title=SPACE_NAME, theme=theme_class()) as demo:
|
573 |
+
# Check if HF_TOKEN is configured to determine configuration panel availability
|
574 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", "").strip()
|
575 |
+
SPACE_ID = os.environ.get("SPACE_ID", "").strip()
|
576 |
|
577 |
+
# Always use tabs structure, Configuration tab visible only with HF_TOKEN
|
578 |
+
with gr.Tabs() as main_tabs:
|
579 |
+
with gr.Tab("Chat U/I"):
|
|
|
580 |
gr.Markdown(f"# {SPACE_NAME}")
|
581 |
gr.Markdown(SPACE_DESCRIPTION)
|
582 |
|
|
|
648 |
outputs=[access_error, chat_section, access_granted]
|
649 |
)
|
650 |
|
651 |
+
# Add Configuration tab (only visible with HF_TOKEN)
|
652 |
+
with gr.Tab("Configuration", visible=(HF_TOKEN and SPACE_ID)) as config_tab:
|
653 |
+
gr.Markdown("## Configuration Management")
|
|
|
|
|
|
|
|
|
654 |
|
655 |
+
# Show authentication status
|
656 |
+
if HF_TOKEN and SPACE_ID:
|
657 |
+
gr.Markdown("✅ **Authenticated** - Configuration changes will be saved to the HuggingFace repository")
|
658 |
+
faculty_auth_state = gr.State(True)
|
659 |
+
else:
|
660 |
+
gr.Markdown("❌ **Not Available** - Set HF_TOKEN and SPACE_ID in Space secrets to enable configuration")
|
661 |
+
faculty_auth_state = gr.State(False)
|
|
|
|
|
|
|
|
|
662 |
|
663 |
+
# Configuration editor (visible if HF_TOKEN is present)
|
664 |
+
with gr.Column(visible=(HF_TOKEN and SPACE_ID)) as faculty_config_section:
|
665 |
gr.Markdown("### Edit Assistant Configuration")
|
666 |
gr.Markdown("⚠️ **Warning:** Changes will affect all users immediately.")
|
667 |
|
|
|
760 |
|
761 |
config_status = gr.Markdown("")
|
762 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
|
764 |
# Save configuration function
|
765 |
+
def save_configuration(is_authenticated, new_prompt, new_model, new_examples, new_temp, new_tokens, *url_values):
|
766 |
if not is_authenticated:
|
767 |
return "Not authenticated"
|
768 |
|
|
|
912 |
|
913 |
return tuple(updates)
|
914 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
915 |
|
916 |
# Connect configuration buttons
|
917 |
save_config_btn.click(
|
918 |
save_configuration,
|
919 |
+
inputs=[faculty_auth_state, edit_system_prompt, edit_model, edit_examples, edit_temperature, edit_max_tokens] + url_fields + [config_locked],
|
920 |
outputs=[config_status]
|
921 |
)
|
922 |
|
|
|
925 |
inputs=[faculty_auth_state],
|
926 |
outputs=[config_status, edit_system_prompt, edit_model, edit_examples, edit_temperature, edit_max_tokens] + url_fields
|
927 |
)
|
|
|
|
|
928 |
|
929 |
if __name__ == "__main__":
|
930 |
demo.launch()
|
config.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
{
|
2 |
"name": "AI Assistant",
|
3 |
"description": "A customizable AI assistant",
|
4 |
-
"system_prompt": "You are a Socratic conversation partner for students in general education courses across all disciplines with strengths in the pebble-in-the-pond learning model, responsive teaching, and constructivist learning principles. Loosely model your approach after Socrates' interlocutor Phaedrus from the eponymous Socratic dialogue, guiding students through source discovery, evaluation, and synthesis using methods of Socratic dialogue. Ask probing questions about explicit and implicit disciplinary knowledge, adapting to their skill level over the conversation and incrementing in complexity based on their demonstrated ability. Connect theory and method to grounded experiences, fostering reflexivity and critical dialogue around research methods and disciplinary practices. Select timely moments to respond with a punchy tone and ironic or self-referential levity.
|
5 |
-
"model": "
|
6 |
"api_key_var": "API_KEY",
|
7 |
-
"temperature": 0.
|
8 |
-
"max_tokens":
|
9 |
"examples": [
|
10 |
"Can you help me understand why the sky is blue?",
|
11 |
"What makes democracy different from other forms of government?",
|
@@ -22,5 +22,5 @@
|
|
22 |
"https://www.reddit.com/r/askphilosophy/comments/k5td4z/is_socratic_method_the_best_way_to_change/"
|
23 |
],
|
24 |
"enable_dynamic_urls": true,
|
25 |
-
"theme": "
|
26 |
}
|
|
|
1 |
{
|
2 |
"name": "AI Assistant",
|
3 |
"description": "A customizable AI assistant",
|
4 |
+
"system_prompt": "You are a Socratic conversation partner for students in general education courses across all disciplines with strengths in the pebble-in-the-pond learning model, responsive teaching, and constructivist learning principles. Loosely model your approach after Socrates' interlocutor Phaedrus from the eponymous Socratic dialogue, guiding students through source discovery, evaluation, and synthesis using methods of Socratic dialogue. Ask probing questions about explicit and implicit disciplinary knowledge, adapting to their skill level over the conversation and incrementing in complexity based on their demonstrated ability. Connect theory and method to grounded experiences, fostering reflexivity and critical dialogue around research methods and disciplinary practices. Select timely moments to respond with a punchy tone and ironic or self-referential levity.",
|
5 |
+
"model": "google/gemini-2.0-flash-001",
|
6 |
"api_key_var": "API_KEY",
|
7 |
+
"temperature": 0.7,
|
8 |
+
"max_tokens": 750,
|
9 |
"examples": [
|
10 |
"Can you help me understand why the sky is blue?",
|
11 |
"What makes democracy different from other forms of government?",
|
|
|
22 |
"https://www.reddit.com/r/askphilosophy/comments/k5td4z/is_socratic_method_the_best_way_to_change/"
|
23 |
],
|
24 |
"enable_dynamic_urls": true,
|
25 |
+
"theme": "Default"
|
26 |
}
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
gradio>=5.38.0
|
2 |
requests>=2.32.3
|
3 |
beautifulsoup4>=4.12.3
|
4 |
-
python-dotenv>=1.0.0
|
|
|
|
1 |
gradio>=5.38.0
|
2 |
requests>=2.32.3
|
3 |
beautifulsoup4>=4.12.3
|
4 |
+
python-dotenv>=1.0.0
|
5 |
+
huggingface_hub>=0.24.0
|