IST199655
commited on
Commit
·
4664330
1
Parent(s):
dfc584d
Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,6 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
|
34 |
|
35 |
def respond(
|
36 |
message: str,
|
37 |
-
history: list[tuple[str, str]],
|
38 |
system_message: str,
|
39 |
max_tokens: int = 128,
|
40 |
temperature: float = 1.0,
|
@@ -62,49 +61,15 @@ def respond(
|
|
62 |
generation_thread.start()
|
63 |
|
64 |
# Stream the output progressively
|
|
|
65 |
for token in streamer: # Append each token to the accumulated text
|
66 |
-
|
|
|
67 |
|
68 |
|
69 |
"""
|
70 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
71 |
"""
|
72 |
-
# demo = gr.ChatInterface(
|
73 |
-
# respond,
|
74 |
-
# additional_inputs=[
|
75 |
-
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
76 |
-
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
77 |
-
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
78 |
-
# gr.Slider(
|
79 |
-
# minimum=0.1,
|
80 |
-
# maximum=1.0,
|
81 |
-
# value=0.95,
|
82 |
-
# step=0.05,
|
83 |
-
# label="Top-p (nucleus sampling)",
|
84 |
-
# ),
|
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:
|
@@ -144,7 +109,7 @@ with gr.Blocks() as demo:
|
|
144 |
|
145 |
# Define functionality
|
146 |
translate_button.click(
|
147 |
-
|
148 |
inputs=[
|
149 |
source_textbox,
|
150 |
system_message_input,
|
|
|
34 |
|
35 |
def respond(
|
36 |
message: str,
|
|
|
37 |
system_message: str,
|
38 |
max_tokens: int = 128,
|
39 |
temperature: float = 1.0,
|
|
|
61 |
generation_thread.start()
|
62 |
|
63 |
# Stream the output progressively
|
64 |
+
generated_text = ""
|
65 |
for token in streamer: # Append each token to the accumulated text
|
66 |
+
generated_text += token
|
67 |
+
yield generated_text
|
68 |
|
69 |
|
70 |
"""
|
71 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
72 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Define the interface
|
75 |
with gr.Blocks() as demo:
|
|
|
109 |
|
110 |
# Define functionality
|
111 |
translate_button.click(
|
112 |
+
respond,
|
113 |
inputs=[
|
114 |
source_textbox,
|
115 |
system_message_input,
|