Spaces:
Sleeping
Sleeping
File size: 854 Bytes
a2c48e6 30c98aa 660fc7d 30c98aa a2c48e6 660fc7d a2c48e6 6dbd92a 30c98aa a2c48e6 30c98aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import requests
import json
import gradio as gr
import os
# Define the function to call the API
def translate(text):
url = os.getenv("TRANSLATION_API_URL")
#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()
|