Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ def respond(
|
|
| 41 |
top_p: float = 1.0,
|
| 42 |
):
|
| 43 |
# Preprocess the input message
|
| 44 |
-
input_text =
|
| 45 |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
| 46 |
|
| 47 |
# Set up the streamer
|
|
@@ -62,10 +62,8 @@ def respond(
|
|
| 62 |
generation_thread.start()
|
| 63 |
|
| 64 |
# Stream the output progressively
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
generated_text += token # Append each token to the accumulated text
|
| 68 |
-
yield generated_text
|
| 69 |
|
| 70 |
|
| 71 |
"""
|
|
@@ -87,6 +85,27 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 87 |
# ],
|
| 88 |
# )
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# Define the interface
|
| 91 |
with gr.Blocks() as demo:
|
| 92 |
gr.Markdown("# Google Translate-like Interface")
|
|
@@ -110,7 +129,7 @@ with gr.Blocks() as demo:
|
|
| 110 |
|
| 111 |
with gr.Accordion("Advanced Settings", open=False):
|
| 112 |
system_message_input = gr.Textbox(
|
| 113 |
-
value="
|
| 114 |
label="System message",
|
| 115 |
)
|
| 116 |
max_tokens_slider = gr.Slider(
|
|
@@ -125,7 +144,7 @@ with gr.Blocks() as demo:
|
|
| 125 |
|
| 126 |
# Define functionality
|
| 127 |
translate_button.click(
|
| 128 |
-
|
| 129 |
inputs=[
|
| 130 |
source_textbox,
|
| 131 |
system_message_input,
|
|
|
|
| 41 |
top_p: float = 1.0,
|
| 42 |
):
|
| 43 |
# Preprocess the input message
|
| 44 |
+
input_text = system_message + " " + message
|
| 45 |
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
| 46 |
|
| 47 |
# Set up the streamer
|
|
|
|
| 62 |
generation_thread.start()
|
| 63 |
|
| 64 |
# Stream the output progressively
|
| 65 |
+
for token in streamer: # Append each token to the accumulated text
|
| 66 |
+
yield token
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
"""
|
|
|
|
| 85 |
# ],
|
| 86 |
# )
|
| 87 |
|
| 88 |
+
# Function to process translation
|
| 89 |
+
def respond_google_translate(
|
| 90 |
+
source_text,
|
| 91 |
+
system_message,
|
| 92 |
+
max_tokens,
|
| 93 |
+
temperature,
|
| 94 |
+
top_p
|
| 95 |
+
):
|
| 96 |
+
# Call the respond function and collect the final response
|
| 97 |
+
result = ""
|
| 98 |
+
for token in respond(
|
| 99 |
+
message=source_text,
|
| 100 |
+
history=[],
|
| 101 |
+
system_message=system_message,
|
| 102 |
+
max_tokens=max_tokens,
|
| 103 |
+
temperature=temperature,
|
| 104 |
+
top_p=top_p,
|
| 105 |
+
):
|
| 106 |
+
result += token # Accumulate the tokens
|
| 107 |
+
return result
|
| 108 |
+
|
| 109 |
# Define the interface
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
gr.Markdown("# Google Translate-like Interface")
|
|
|
|
| 129 |
|
| 130 |
with gr.Accordion("Advanced Settings", open=False):
|
| 131 |
system_message_input = gr.Textbox(
|
| 132 |
+
value="translate English to French:",
|
| 133 |
label="System message",
|
| 134 |
)
|
| 135 |
max_tokens_slider = gr.Slider(
|
|
|
|
| 144 |
|
| 145 |
# Define functionality
|
| 146 |
translate_button.click(
|
| 147 |
+
respond_google_translate,
|
| 148 |
inputs=[
|
| 149 |
source_textbox,
|
| 150 |
system_message_input,
|