Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,10 @@ body {
|
|
45 |
|
46 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
47 |
|
48 |
-
def respond(
|
|
|
|
|
|
|
49 |
message,
|
50 |
history: list[tuple[str, str]],
|
51 |
system_message,
|
@@ -76,15 +79,49 @@ def respond(
|
|
76 |
response += token
|
77 |
yield response
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
with gr.Blocks(css=css) as demo:
|
80 |
-
# Title Markdown block
|
81 |
gr.Markdown("French Tutor", elem_id="custom-title")
|
82 |
|
83 |
with gr.Column(elem_id="chat-panel"):
|
84 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
)
|
89 |
max_tokens = gr.Slider(
|
90 |
minimum=1,
|
|
|
45 |
|
46 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
47 |
|
48 |
+
def respond(message, history, level, max_tokens, temperature, top_p):
|
49 |
+
system_message = level_to_prompt(level)
|
50 |
+
...
|
51 |
+
|
52 |
message,
|
53 |
history: list[tuple[str, str]],
|
54 |
system_message,
|
|
|
79 |
response += token
|
80 |
yield response
|
81 |
|
82 |
+
def level_to_prompt(level):
|
83 |
+
mapping = {
|
84 |
+
"A1": "You are a friendly French tutor. Speak mostly in English, use simple French, and explain everything.",
|
85 |
+
"A2": "You are a patient French tutor. Use short French phrases, but explain them in English.",
|
86 |
+
"B1": "You are a helpful French tutor. Speak mostly in French with English explanations when needed.",
|
87 |
+
"B2": "You are a French tutor. Speak primarily in French. Use English only when absolutely necessary.",
|
88 |
+
"C1": "You are a native French tutor. Speak only in French, but be clear and articulate.",
|
89 |
+
"C2": "You are a native French professor. Speak in complex and natural French. Avoid English."
|
90 |
+
}
|
91 |
+
return mapping.get(level, mapping["A1"]) # Fallback to A1
|
92 |
+
|
93 |
with gr.Blocks(css=css) as demo:
|
|
|
94 |
gr.Markdown("French Tutor", elem_id="custom-title")
|
95 |
|
96 |
with gr.Column(elem_id="chat-panel"):
|
97 |
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
98 |
+
level = gr.Dropdown(
|
99 |
+
choices=["A1", "A2", "B1", "B2", "C1", "C2"],
|
100 |
+
value="A1",
|
101 |
+
label="Your French Level (CEFR)"
|
102 |
+
)
|
103 |
+
max_tokens = gr.Slider(1, 2048, value=512, step=1, label="Response Length")
|
104 |
+
temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Creativity")
|
105 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Dynamic Text")
|
106 |
+
|
107 |
+
gr.ChatInterface(
|
108 |
+
fn=respond,
|
109 |
+
additional_inputs=[
|
110 |
+
level, # replace system_message
|
111 |
+
max_tokens, temperature, top_p
|
112 |
+
]
|
113 |
+
)
|
114 |
+
|
115 |
+
|
116 |
+
with gr.Blocks(css=css) as demo:
|
117 |
+
# Title Markdown block
|
118 |
+
gr.Markdown("French Tutor", elem_id="custom-title")
|
119 |
+
|
120 |
+
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
121 |
+
level = gr.Dropdown(
|
122 |
+
choices=["A1", "A2", "B1", "B2", "C1", "C2"],
|
123 |
+
value="A1",
|
124 |
+
label="Your French Level (CEFR)"
|
125 |
)
|
126 |
max_tokens = gr.Slider(
|
127 |
minimum=1,
|