from transformers.utils import logging from language_directions import * logging.set_verbosity_error() import warnings warnings.filterwarnings("ignore", message="Using the model-agnostic default `max_length`") import os import gradio as gr from transformers import pipeline pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base") def translate(input_text, source, target): try: # Helsinki-NLP/opus-mt-en-sq model = f"Helsinki-NLP/opus-mt-{source}-{target}" pipe = pipeline("translation", model=model) translation = pipe(input_text) return translation[0]['translation_text'], input_text except KeyError: return "", f"Error: Translation direction {source_readable} to {target} is not supported by Helsinki Translation Models" def launch(input): out = pipe(input) context_str = out[0]['generated_text'] translate_str = translate(context_str, 'en', 'sq') return translate_str iface.launch(share=True) iface = gr.Interface(launch, inputs=gr.Image(type='pil'), outputs="text") # iface.launch(share=True, # server_port=int(os.environ['PORT1'])) iface.close()