Ra-Is's picture
Update app.py
6dbd92a verified
raw
history blame
800 Bytes
import requests
import json
import gradio as gr
# Define the function to call the API
def translate(text):
url = "https://xayq0bvi0h.execute-api.eu-west-2.amazonaws.com/api/translate"
payload = json.dumps({
"text": text
})
headers = {
'Content-Type': 'application/json'
}
# Make the API request
response = requests.request("POST", url, headers=headers, data=payload)
# Parse the response and extract the translation
response_data = response.json() # Parse the JSON response
translation = response_data.get("translation", "Translation not found") # Get the translation
return translation
# Create the Gradio interface
demo = gr.Interface(fn=translate, inputs="text", outputs="text")
# Launch the Gradio app
demo.launch()