Heit39 commited on
Commit
481b521
·
verified ·
1 Parent(s): 7fe3527

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -6
app.py CHANGED
@@ -87,12 +87,75 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
87
  # ],
88
  # )
89
 
90
- demo = gr.Interface(fn=respond,
91
- inputs=[gr.Textbox(label="Input Text", placeholder="Input Text To Be Translated")],
92
- outputs=gr.Textbox(label="Translation"),
93
- title="tTranslatorR-Opus"
94
- )
95
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  if __name__ == "__main__":
98
  demo.launch()
 
87
  # ],
88
  # )
89
 
90
+ # Function to process translation
91
+ def respond_google_translate(
92
+ source_text,
93
+ system_message,
94
+ max_tokens,
95
+ temperature,
96
+ top_p
97
+ ):
98
+ # Call the respond function and collect the final response
99
+ result = ""
100
+ for token in respond(
101
+ message=source_text,
102
+ history=[],
103
+ system_message=system_message,
104
+ max_tokens=max_tokens,
105
+ temperature=temperature,
106
+ top_p=top_p,
107
+ ):
108
+ result += token # Accumulate the tokens
109
+ return result
110
+
111
+ # Define the interface
112
+ with gr.Blocks() as demo:
113
+ gr.Markdown("# Google Translate-like Interface")
114
+
115
+ with gr.Row():
116
+ with gr.Column():
117
+ source_textbox = gr.Textbox(
118
+ placeholder="Enter text in English...",
119
+ label="Source Text (English)",
120
+ lines=5,
121
+ )
122
+ with gr.Column():
123
+ translated_textbox = gr.Textbox(
124
+ placeholder="Translation will appear here...",
125
+ label="Translated Text (French)",
126
+ lines=5,
127
+ interactive=False,
128
+ )
129
+
130
+ translate_button = gr.Button("Translate")
131
+
132
+ with gr.Accordion("Advanced Settings", open=False):
133
+ system_message_input = gr.Textbox(
134
+ value="You are a friendly Chatbot.",
135
+ label="System message",
136
+ )
137
+ max_tokens_slider = gr.Slider(
138
+ minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"
139
+ )
140
+ temperature_slider = gr.Slider(
141
+ minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"
142
+ )
143
+ top_p_slider = gr.Slider(
144
+ minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"
145
+ )
146
+
147
+ # Define functionality
148
+ translate_button.click(
149
+ respond_google_translate,
150
+ inputs=[
151
+ source_textbox,
152
+ system_message_input,
153
+ max_tokens_slider,
154
+ temperature_slider,
155
+ top_p_slider,
156
+ ],
157
+ outputs=translated_textbox,
158
+ )
159
 
160
  if __name__ == "__main__":
161
  demo.launch()