Spaces:
Runtime error
Runtime error
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() | |