Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,11 @@ import gradio as gr
|
|
4 |
import os
|
5 |
|
6 |
# Define the function to call the API
|
7 |
-
def translate(text):
|
8 |
url = os.getenv("TRANSLATION_URL")
|
9 |
payload = json.dumps({
|
10 |
-
"text": text
|
|
|
11 |
})
|
12 |
headers = {
|
13 |
'Content-Type': 'application/json'
|
@@ -22,10 +23,12 @@ def translate(text):
|
|
22 |
|
23 |
return translation
|
24 |
|
25 |
-
# Create the Gradio interface with a
|
26 |
-
textbox = gr.Textbox(placeholder="Enter
|
|
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
# Launch the Gradio app
|
31 |
demo.launch()
|
|
|
4 |
import os
|
5 |
|
6 |
# Define the function to call the API
|
7 |
+
def translate(text, lang):
|
8 |
url = os.getenv("TRANSLATION_URL")
|
9 |
payload = json.dumps({
|
10 |
+
"text": text,
|
11 |
+
"lang": lang # Add language to the payload
|
12 |
})
|
13 |
headers = {
|
14 |
'Content-Type': 'application/json'
|
|
|
23 |
|
24 |
return translation
|
25 |
|
26 |
+
# Create the Gradio interface with a textbox and dropdown
|
27 |
+
textbox = gr.Textbox(placeholder="Enter text to translate...")
|
28 |
+
dropdown = gr.Dropdown(choices=["english-twi", "twi-english"], label="Select Translation Language")
|
29 |
|
30 |
+
# Pass both inputs to the translate function
|
31 |
+
demo = gr.Interface(fn=translate, inputs=[textbox, dropdown], outputs="text")
|
32 |
|
33 |
# Launch the Gradio app
|
34 |
demo.launch()
|