Ra-Is commited on
Commit
e1b3d3f
1 Parent(s): 8cbfe60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
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 placeholder in the text box
26
- textbox = gr.Textbox(placeholder="Enter English text to translate...")
 
27
 
28
- demo = gr.Interface(fn=translate, inputs=textbox, outputs="text")
 
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()