prototype-1 / app.py
andyski's picture
Update app.py
4cfbb07 verified
Raw History Blame Contribute Delete
1.03 kB
from transformers import pipeline
import gradio, requests
#DEFINE MODEL TRHU PIPELINE
pipeline = pipeline(task="translation", model="meta-llama/Meta-Llama-3-70B")
#MAKING THE FUNCION FOR API IMPLE
# def generate_translation(text_req, parameters=None,API_URL="https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-zh-en"):
# http_header = {"Authorization": f"Bearer {{dlaitoken1}}"}
# data_input = {"inputs": text_req, "parameters": parameters}
# http_response_handler = requests.request("POST", API_URL, headers=http_header, data=data_input)
# http_response_formatted = http_response_handler.json()
# return http_response_formatted
#MAKING THE FUNCTION FOR PIPELINE IMPLE
def generate(text_req):
return pipeline(text_req)
#GRADIO INTERFACE
gradio_interface = gradio.Interface(fn=generate, inputs=[gradio.Textbox(label="WHAT DO YOU WANT TO TRANSLATE", lines=2)], outputs=[gradio.Textbox(label="TRANSLATION")], title="TRANSLATION APP")
if __name__ == "__main__":
gradio_interface.launch()