Spaces:
Runtime error
Runtime error
File size: 1,511 Bytes
d76d7a7 18ae9dd d76d7a7 67f7693 18ae9dd 069f1ba 18ae9dd 069f1ba 18ae9dd 745ec12 18ae9dd 745ec12 18ae9dd |
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 32 33 34 35 36 37 38 39 40 |
import gradio as gr
import boto3
import os
hf_token = os.environ.get("HF_TOKEN")
m=gr.load("imcapsule/tasomi-capsule", src="models",hf_token=hf_token)
def detect_language(text):
# Initialize the Comprehend client
comprehend = boto3.client('comprehend', region_name='ap-northeast-2')
# Call DetectDominantLanguage API
response = comprehend.detect_dominant_language(Text=text)
# Extract the detected language
detected_language = response['Languages'][0]['LanguageCode']
return detected_language
def translate_and_predict(text):
"""Translates text and generates an image using Stable Diffusion."""
source_language_code=detect_language(text)
# Translate input text
translate = boto3.client('translate', region_name='ap-northeast-2')
target_language_code="en"
print("source_language_code:" , source_language_code)
translation_result = translate.translate_text(Text=text, SourceLanguageCode=source_language_code, TargetLanguageCode=target_language_code)
translated_text = translation_result.get('TranslatedText')
print("translated_text:" , translated_text)
image_path=m(translated_text)
return image_path
# Define the Gradio interface
iface = gr.Interface(
fn=translate_and_predict, # Since we're only displaying an image, there's no function to call
inputs=["text"], # Input: text, source language, target language
outputs="image", # Output: generated image
title="Image Viewer",
)
# Launch the interface
iface.launch()
|