Spaces:
Running
Running
Upload 4 files
Browse files- README.md +2 -2
- app.py +47 -17
- config.json +6 -6
README.md
CHANGED
@@ -8,12 +8,12 @@ sdk_version: 5.39.0
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
-
short_description: Italian language learning for
|
12 |
---
|
13 |
|
14 |
# Language Learning Partner
|
15 |
|
16 |
-
|
17 |
|
18 |
## Quick Setup
|
19 |
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
+
short_description: Italian language learning partner for beginner Italian conve
|
12 |
---
|
13 |
|
14 |
# Language Learning Partner
|
15 |
|
16 |
+
Italian language learning partner for beginner Italian conversation practice
|
17 |
|
18 |
## Quick Setup
|
19 |
|
app.py
CHANGED
@@ -19,16 +19,17 @@ SPACE_DESCRIPTION = 'Italian language learning partner for beginner Italian conv
|
|
19 |
DEFAULT_CONFIG = {
|
20 |
'name': SPACE_NAME,
|
21 |
'description': SPACE_DESCRIPTION,
|
22 |
-
'system_prompt': "You are a native Italian speaker serving as a conversational partner for university students in an Italian 101 class. Students will interact and converse with you in Italian, and you must respond EXCLUSIVELY IN ITALIAN without providing English translations, using vocabulary appropriate for beginner-level Italian 101 students.
|
23 |
'temperature': 0.5,
|
24 |
'max_tokens': 250,
|
25 |
'model': 'google/gemma-3-27b-it',
|
26 |
'api_key_var': 'API_KEY',
|
27 |
'theme': 'Default',
|
28 |
-
'grounding_urls': [],
|
29 |
'enable_dynamic_urls': True,
|
30 |
'enable_file_upload': True,
|
31 |
'examples': ['Ciao! Come stai oggi?', 'Mi piace giocare a calcio. E tu?', 'Cosa mangi di solito a colazione?', 'A che ora ti svegli la mattina?', 'Qual è il tuo sport preferito?'],
|
|
|
32 |
'locked': False
|
33 |
}
|
34 |
|
@@ -136,6 +137,7 @@ THEME = config.get('theme', DEFAULT_CONFIG['theme'])
|
|
136 |
GROUNDING_URLS = config.get('grounding_urls', DEFAULT_CONFIG['grounding_urls'])
|
137 |
ENABLE_DYNAMIC_URLS = config.get('enable_dynamic_urls', DEFAULT_CONFIG['enable_dynamic_urls'])
|
138 |
ENABLE_FILE_UPLOAD = config.get('enable_file_upload', DEFAULT_CONFIG.get('enable_file_upload', True))
|
|
|
139 |
|
140 |
# Environment variables
|
141 |
ACCESS_CODE = os.environ.get("ACCESS_CODE")
|
@@ -395,8 +397,19 @@ Get your API key at: https://openrouter.ai/keys"""
|
|
395 |
dynamic_context += f"\n{content}"
|
396 |
grounding_context += dynamic_context
|
397 |
|
398 |
-
# Build messages
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
|
401 |
# Add conversation history
|
402 |
for msg in history:
|
@@ -406,16 +419,10 @@ Get your API key at: https://openrouter.ai/keys"""
|
|
406 |
"content": msg['content']
|
407 |
})
|
408 |
|
409 |
-
# Add current message
|
410 |
-
full_message = message
|
411 |
-
if grounding_context:
|
412 |
-
full_message = f"{grounding_context}\n\n{message}"
|
413 |
-
if file_context:
|
414 |
-
full_message = f"{file_context}\n\n{full_message}"
|
415 |
-
|
416 |
messages.append({
|
417 |
"role": "user",
|
418 |
-
"content":
|
419 |
})
|
420 |
|
421 |
# Make API request
|
@@ -751,6 +758,27 @@ def create_interface():
|
|
751 |
allow_custom_value=True
|
752 |
)
|
753 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
754 |
edit_description = gr.Textbox(
|
755 |
label="Description",
|
756 |
value=config.get('description', ''),
|
@@ -814,7 +842,7 @@ def create_interface():
|
|
814 |
|
815 |
config_status = gr.Markdown()
|
816 |
|
817 |
-
def save_configuration(name, description, system_prompt, model, temp, tokens, examples, grounding_urls, enable_dynamic_urls, enable_file_upload):
|
818 |
"""Save updated configuration"""
|
819 |
try:
|
820 |
updated_config = config.copy()
|
@@ -823,6 +851,7 @@ def create_interface():
|
|
823 |
'description': description,
|
824 |
'system_prompt': system_prompt,
|
825 |
'model': model,
|
|
|
826 |
'temperature': temp,
|
827 |
'max_tokens': int(tokens),
|
828 |
'examples': [ex.strip() for ex in examples.split('\n') if ex.strip()],
|
@@ -867,7 +896,7 @@ def create_interface():
|
|
867 |
|
868 |
save_btn.click(
|
869 |
save_configuration,
|
870 |
-
inputs=[edit_name, edit_description, edit_system_prompt, edit_model,
|
871 |
edit_temperature, edit_max_tokens, edit_examples, edit_grounding_urls,
|
872 |
edit_enable_dynamic_urls, edit_enable_file_upload],
|
873 |
outputs=[config_status]
|
@@ -882,6 +911,7 @@ def create_interface():
|
|
882 |
DEFAULT_CONFIG['description'],
|
883 |
DEFAULT_CONFIG['system_prompt'],
|
884 |
DEFAULT_CONFIG['model'],
|
|
|
885 |
DEFAULT_CONFIG['temperature'],
|
886 |
DEFAULT_CONFIG['max_tokens'],
|
887 |
'\n'.join(DEFAULT_CONFIG['examples']),
|
@@ -891,13 +921,13 @@ def create_interface():
|
|
891 |
"✅ Reset to default configuration"
|
892 |
)
|
893 |
else:
|
894 |
-
return (*[gr.update() for _ in range(
|
895 |
except Exception as e:
|
896 |
-
return (*[gr.update() for _ in range(
|
897 |
|
898 |
reset_btn.click(
|
899 |
reset_configuration,
|
900 |
-
outputs=[edit_name, edit_description, edit_system_prompt, edit_model,
|
901 |
edit_temperature, edit_max_tokens, edit_examples, edit_grounding_urls,
|
902 |
edit_enable_dynamic_urls, edit_enable_file_upload, config_status]
|
903 |
)
|
|
|
19 |
DEFAULT_CONFIG = {
|
20 |
'name': SPACE_NAME,
|
21 |
'description': SPACE_DESCRIPTION,
|
22 |
+
'system_prompt': "You are Domenico from Sicily, a Juventus football fan, native Italian speaker serving as a conversational partner for university students in an Italian 101 class. Students will interact and converse with you in Italian, and you must respond EXCLUSIVELY IN ITALIAN without providing English translations, using vocabulary appropriate for beginner-level Italian 101 students. Focus your responses on topics suitable for beginners such as sports, daily life, routines, food, numbers, and hobbies. When students make errors, model the correct forms naturally in your response without explicitly pointing out mistakes, allowing them to learn through exposure to proper usage. Recognize when students demonstrate more advanced abilities and adjust your language complexity accordingly, while ensuring your Italian remains error-free. Keep all responses between 5-50 words, making sure sentences are grammatically complete. Expect to finish every response in under 300 tokens. --- KNOWLEDGE CUTOFF WARNINGS: 1. Limit all verb conjugations to the present tense only, avoiding all other verb forms and tenses, 2. Favor vocabulary words and grammar from the fetched URL page. 3. Address students using the informal second-person singular 'tu' form.",
|
23 |
'temperature': 0.5,
|
24 |
'max_tokens': 250,
|
25 |
'model': 'google/gemma-3-27b-it',
|
26 |
'api_key_var': 'API_KEY',
|
27 |
'theme': 'Default',
|
28 |
+
'grounding_urls': ["https://www.pnac.org/wp-content/uploads/Italian-Study-Guide.pdf"],
|
29 |
'enable_dynamic_urls': True,
|
30 |
'enable_file_upload': True,
|
31 |
'examples': ['Ciao! Come stai oggi?', 'Mi piace giocare a calcio. E tu?', 'Cosa mangi di solito a colazione?', 'A che ora ti svegli la mattina?', 'Qual è il tuo sport preferito?'],
|
32 |
+
'language': 'Italian',
|
33 |
'locked': False
|
34 |
}
|
35 |
|
|
|
137 |
GROUNDING_URLS = config.get('grounding_urls', DEFAULT_CONFIG['grounding_urls'])
|
138 |
ENABLE_DYNAMIC_URLS = config.get('enable_dynamic_urls', DEFAULT_CONFIG['enable_dynamic_urls'])
|
139 |
ENABLE_FILE_UPLOAD = config.get('enable_file_upload', DEFAULT_CONFIG.get('enable_file_upload', True))
|
140 |
+
LANGUAGE = config.get('language', DEFAULT_CONFIG.get('language', 'English'))
|
141 |
|
142 |
# Environment variables
|
143 |
ACCESS_CODE = os.environ.get("ACCESS_CODE")
|
|
|
397 |
dynamic_context += f"\n{content}"
|
398 |
grounding_context += dynamic_context
|
399 |
|
400 |
+
# Build messages with grounding context and file context in system prompt
|
401 |
+
system_content = SYSTEM_PROMPT
|
402 |
+
|
403 |
+
# Add language instruction if not English
|
404 |
+
if LANGUAGE != 'English':
|
405 |
+
system_content += f"\n\nIMPORTANT: You must respond EXCLUSIVELY in {LANGUAGE}. All your responses should be written entirely in {LANGUAGE}, even when user input is in a different language, particularly English."
|
406 |
+
|
407 |
+
if grounding_context:
|
408 |
+
system_content = f"{system_content}\n\n{grounding_context}"
|
409 |
+
if file_context:
|
410 |
+
system_content = f"{system_content}\n\n{file_context}"
|
411 |
+
|
412 |
+
messages = [{"role": "system", "content": system_content}]
|
413 |
|
414 |
# Add conversation history
|
415 |
for msg in history:
|
|
|
419 |
"content": msg['content']
|
420 |
})
|
421 |
|
422 |
+
# Add current message
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
messages.append({
|
424 |
"role": "user",
|
425 |
+
"content": message
|
426 |
})
|
427 |
|
428 |
# Make API request
|
|
|
758 |
allow_custom_value=True
|
759 |
)
|
760 |
|
761 |
+
edit_language = gr.Dropdown(
|
762 |
+
label="Language",
|
763 |
+
choices=[
|
764 |
+
"Arabic",
|
765 |
+
"Bengali",
|
766 |
+
"English",
|
767 |
+
"French",
|
768 |
+
"German",
|
769 |
+
"Hindi",
|
770 |
+
"Italian",
|
771 |
+
"Japanese",
|
772 |
+
"Korean",
|
773 |
+
"Mandarin",
|
774 |
+
"Portuguese",
|
775 |
+
"Russian",
|
776 |
+
"Spanish",
|
777 |
+
"Turkish"
|
778 |
+
],
|
779 |
+
value=config.get('language', 'English')
|
780 |
+
)
|
781 |
+
|
782 |
edit_description = gr.Textbox(
|
783 |
label="Description",
|
784 |
value=config.get('description', ''),
|
|
|
842 |
|
843 |
config_status = gr.Markdown()
|
844 |
|
845 |
+
def save_configuration(name, description, system_prompt, model, language, temp, tokens, examples, grounding_urls, enable_dynamic_urls, enable_file_upload):
|
846 |
"""Save updated configuration"""
|
847 |
try:
|
848 |
updated_config = config.copy()
|
|
|
851 |
'description': description,
|
852 |
'system_prompt': system_prompt,
|
853 |
'model': model,
|
854 |
+
'language': language,
|
855 |
'temperature': temp,
|
856 |
'max_tokens': int(tokens),
|
857 |
'examples': [ex.strip() for ex in examples.split('\n') if ex.strip()],
|
|
|
896 |
|
897 |
save_btn.click(
|
898 |
save_configuration,
|
899 |
+
inputs=[edit_name, edit_description, edit_system_prompt, edit_model, edit_language,
|
900 |
edit_temperature, edit_max_tokens, edit_examples, edit_grounding_urls,
|
901 |
edit_enable_dynamic_urls, edit_enable_file_upload],
|
902 |
outputs=[config_status]
|
|
|
911 |
DEFAULT_CONFIG['description'],
|
912 |
DEFAULT_CONFIG['system_prompt'],
|
913 |
DEFAULT_CONFIG['model'],
|
914 |
+
DEFAULT_CONFIG.get('language', 'English'),
|
915 |
DEFAULT_CONFIG['temperature'],
|
916 |
DEFAULT_CONFIG['max_tokens'],
|
917 |
'\n'.join(DEFAULT_CONFIG['examples']),
|
|
|
921 |
"✅ Reset to default configuration"
|
922 |
)
|
923 |
else:
|
924 |
+
return (*[gr.update() for _ in range(11)], "❌ Failed to reset")
|
925 |
except Exception as e:
|
926 |
+
return (*[gr.update() for _ in range(11)], f"❌ Error: {str(e)}")
|
927 |
|
928 |
reset_btn.click(
|
929 |
reset_configuration,
|
930 |
+
outputs=[edit_name, edit_description, edit_system_prompt, edit_model, edit_language,
|
931 |
edit_temperature, edit_max_tokens, edit_examples, edit_grounding_urls,
|
932 |
edit_enable_dynamic_urls, edit_enable_file_upload, config_status]
|
933 |
)
|
config.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
{
|
2 |
"name": "Language Learning Partner",
|
3 |
-
"tagline": "
|
4 |
-
"description": "
|
5 |
-
"system_prompt": "You are Domenico from Sicily, a Juventus football fan,
|
6 |
"model": "google/gemma-3-27b-it",
|
|
|
7 |
"api_key_var": "API_KEY",
|
8 |
"temperature": 0.5,
|
9 |
-
"max_tokens":
|
10 |
"examples": [
|
11 |
"Ciao! Come stai oggi?",
|
12 |
"Mi piace giocare a calcio. E tu?",
|
@@ -19,6 +20,5 @@
|
|
19 |
],
|
20 |
"enable_dynamic_urls": true,
|
21 |
"enable_file_upload": true,
|
22 |
-
"theme": "
|
23 |
-
"locked": false
|
24 |
}
|
|
|
1 |
{
|
2 |
"name": "Language Learning Partner",
|
3 |
+
"tagline": "Italian language learning partner for beginner Italian conve",
|
4 |
+
"description": "Italian language learning partner for beginner Italian conversation practice",
|
5 |
+
"system_prompt": "You are Domenico from Sicily, a Juventus football fan, native Italian speaker serving as a conversational partner for university students in an Italian 101 class. Students will interact and converse with you in Italian, and you must respond EXCLUSIVELY IN ITALIAN without providing English translations, using vocabulary appropriate for beginner-level Italian 101 students. Focus your responses on topics suitable for beginners such as sports, daily life, routines, food, numbers, and hobbies. When students make errors, model the correct forms naturally in your response without explicitly pointing out mistakes, allowing them to learn through exposure to proper usage. Recognize when students demonstrate more advanced abilities and adjust your language complexity accordingly, while ensuring your Italian remains error-free. Keep all responses between 5-50 words, making sure sentences are grammatically complete. Expect to finish every response in under 300 tokens. --- KNOWLEDGE CUTOFF WARNINGS: 1. Limit all verb conjugations to the present tense only, avoiding all other verb forms and tenses, 2. Favor vocabulary words and grammar from the fetched URL page. 3. Address students using the informal second-person singular 'tu' form.",
|
6 |
"model": "google/gemma-3-27b-it",
|
7 |
+
"language": "Italian",
|
8 |
"api_key_var": "API_KEY",
|
9 |
"temperature": 0.5,
|
10 |
+
"max_tokens": 250,
|
11 |
"examples": [
|
12 |
"Ciao! Come stai oggi?",
|
13 |
"Mi piace giocare a calcio. E tu?",
|
|
|
20 |
],
|
21 |
"enable_dynamic_urls": true,
|
22 |
"enable_file_upload": true,
|
23 |
+
"theme": "Default"
|
|
|
24 |
}
|