andyski commited on
Commit
d5c55f2
·
verified ·
1 Parent(s): cdb829f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -4,19 +4,22 @@ import gradio, requests
4
  #DEFINE MODEL TRHU PIPELINE
5
  pipeline = pipeline(task="translation", model="Helsinki-NLP/opus-mt-zh-en")
6
 
7
- #MAKING THE FUNCION
8
- def generate_translation(text_req, parameters=None,API_URL="https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-zh-en"):
9
- http_header = {"Authorization": f"Bearer {{dlaitoken1}}"}
10
- data_input = {"inputs": text_req, "parameters": parameters}
11
 
12
- http_response_handler = requests.request("POST", API_URL, headers=http_header, data=data_input)
13
- http_response_formatted = http_response_handler.json()
14
 
15
- return http_response_formatted
 
 
 
16
 
17
 
18
  #GRADIO INTERFACE
19
- gradio_interface = gradio.Interface(fn=generate_translation, inputs=[gradio.Textbox(label="WHAT DO YOU WANT TO TRANSLATE", lines=2)], outputs=[gradio.Textbox(label="TRANSLATION")], title="TRANSLATION APP")
20
 
21
  if __name__ == "__main__":
22
  gradio_interface.launch()
 
4
  #DEFINE MODEL TRHU PIPELINE
5
  pipeline = pipeline(task="translation", model="Helsinki-NLP/opus-mt-zh-en")
6
 
7
+ # #MAKING THE FUNCION
8
+ # def generate_translation(text_req, parameters=None,API_URL="https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-zh-en"):
9
+ # http_header = {"Authorization": f"Bearer {{dlaitoken1}}"}
10
+ # data_input = {"inputs": text_req, "parameters": parameters}
11
 
12
+ # http_response_handler = requests.request("POST", API_URL, headers=http_header, data=data_input)
13
+ # http_response_formatted = http_response_handler.json()
14
 
15
+ # return http_response_formatted
16
+
17
+ def generate(text_req):
18
+ return pipeline(text_req)
19
 
20
 
21
  #GRADIO INTERFACE
22
+ 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")
23
 
24
  if __name__ == "__main__":
25
  gradio_interface.launch()