Spaces:
Sleeping
Sleeping
Some enhancements related to lang
Browse files
app.py
CHANGED
|
@@ -151,7 +151,7 @@ class rfTranslatedText(BaseModel):
|
|
| 151 |
class rfGenericText(BaseModel):
|
| 152 |
text: str = Field(description='The text result')
|
| 153 |
|
| 154 |
-
def ChatFunc(message, history):
|
| 155 |
|
| 156 |
|
| 157 |
# Determinar se o user quer fazer uma nova pesquisa!
|
|
@@ -220,9 +220,13 @@ def ChatFunc(message, history):
|
|
| 220 |
Return both source language and translated text.
|
| 221 |
""",message, rfTranslatedText)
|
| 222 |
Question = LLMResult.message.parsed.text;
|
| 223 |
-
SourceLang = LLMResult.message.parsed.lang;
|
| 224 |
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
yield m("searching...")
|
| 228 |
try:
|
|
@@ -326,21 +330,41 @@ def ChatFunc(message, history):
|
|
| 326 |
yield m.done()
|
| 327 |
|
| 328 |
|
|
|
|
| 329 |
resultTable = gr.Dataframe(datatype = ['html','number','number'], interactive = False, show_search = "search");
|
| 330 |
|
| 331 |
with gr.Blocks(fill_height=True) as demo:
|
| 332 |
|
| 333 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
|
|
|
| 335 |
with gr.Tab("Chat", scale = 1):
|
| 336 |
ChatTextBox = gr.Textbox(max_length = 500, info = "Which script are you looking for?", submit_btn = True);
|
| 337 |
|
| 338 |
gr.ChatInterface(
|
| 339 |
ChatFunc
|
| 340 |
,additional_outputs=[resultTable]
|
|
|
|
| 341 |
,type="messages"
|
| 342 |
,textbox = ChatTextBox
|
| 343 |
)
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
with gr.Tab("Rank"):
|
| 346 |
resultTable.render();
|
|
|
|
| 151 |
class rfGenericText(BaseModel):
|
| 152 |
text: str = Field(description='The text result')
|
| 153 |
|
| 154 |
+
def ChatFunc(message, history, LangMode, ChooseLang):
|
| 155 |
|
| 156 |
|
| 157 |
# Determinar se o user quer fazer uma nova pesquisa!
|
|
|
|
| 220 |
Return both source language and translated text.
|
| 221 |
""",message, rfTranslatedText)
|
| 222 |
Question = LLMResult.message.parsed.text;
|
|
|
|
| 223 |
|
| 224 |
+
if LangMode == "auto":
|
| 225 |
+
SourceLang = LLMResult.message.parsed.lang;
|
| 226 |
+
else:
|
| 227 |
+
SourceLang = ChooseLang
|
| 228 |
+
|
| 229 |
+
yield m(f"Lang:{SourceLang}({LangMode}), English Prompt: {Question}")
|
| 230 |
|
| 231 |
yield m("searching...")
|
| 232 |
try:
|
|
|
|
| 330 |
yield m.done()
|
| 331 |
|
| 332 |
|
| 333 |
+
|
| 334 |
resultTable = gr.Dataframe(datatype = ['html','number','number'], interactive = False, show_search = "search");
|
| 335 |
|
| 336 |
with gr.Blocks(fill_height=True) as demo:
|
| 337 |
|
| 338 |
with gr.Column():
|
| 339 |
+
|
| 340 |
+
tabSettings = gr.Tab("Settings", render = False)
|
| 341 |
+
|
| 342 |
+
with tabSettings:
|
| 343 |
+
LangOpts = gr.Radio([("Auto Detect from text","auto"), ("Use browser language","browser")], value="auto", label="Language", info="Choose lang used by AI to answer you!")
|
| 344 |
+
LangChoose = gr.Textbox(info = "This will be filled with detect browser language, but you can change")
|
| 345 |
+
|
| 346 |
+
LangOpts.change(None, [LangOpts],[LangChoose], js = """
|
| 347 |
+
function(opt){
|
| 348 |
+
if(opt == "browser"){
|
| 349 |
+
return navigator ? navigator.language : "en-US";
|
| 350 |
+
}
|
| 351 |
+
}
|
| 352 |
+
""")
|
| 353 |
|
| 354 |
+
|
| 355 |
with gr.Tab("Chat", scale = 1):
|
| 356 |
ChatTextBox = gr.Textbox(max_length = 500, info = "Which script are you looking for?", submit_btn = True);
|
| 357 |
|
| 358 |
gr.ChatInterface(
|
| 359 |
ChatFunc
|
| 360 |
,additional_outputs=[resultTable]
|
| 361 |
+
,additional_inputs=[LangOpts,LangChoose]
|
| 362 |
,type="messages"
|
| 363 |
,textbox = ChatTextBox
|
| 364 |
)
|
| 365 |
+
|
| 366 |
+
tabSettings.render()
|
| 367 |
+
|
| 368 |
|
| 369 |
with gr.Tab("Rank"):
|
| 370 |
resultTable.render();
|