Spaces:
Runtime error
Runtime error
Commit
·
37e1efb
1
Parent(s):
5330b0e
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,23 @@ import IPython.display
|
|
| 6 |
from PIL import Image
|
| 7 |
import base64
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
#def greet(name):
|
| 10 |
# return "Hello " + name +os.environ['HF_TOKENS']
|
| 11 |
|
|
@@ -19,26 +36,26 @@ import base64
|
|
| 19 |
#gr.Textbox(os.environ['HF_TOKENS'])
|
| 20 |
|
| 21 |
#Image-to-text endpoint
|
| 22 |
-
def get_completion(inputs, parameters=None, ENDPOINT_URL="http://internal-aws-prod-internal-revproxy-alb-11660607.us-west-1.elb.amazonaws.com/rev-proxy/huggingface/itt"):
|
| 23 |
-
headers = {
|
| 24 |
-
"Authorization": f"Bearer {os.environ['HF_TOKENS']}",
|
| 25 |
-
"Content-Type": "application/json"
|
| 26 |
-
}
|
| 27 |
-
data = { "inputs": inputs }
|
| 28 |
-
if parameters is not None:
|
| 29 |
-
data.update({"parameters": parameters})
|
| 30 |
-
response = requests.request("POST",
|
| 31 |
-
ENDPOINT_URL,
|
| 32 |
-
headers=headers,
|
| 33 |
-
data=json.dumps(data))
|
| 34 |
-
return json.loads(response.content.decode("utf-8"))
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
demo = gr.Interface(
|
| 38 |
-
fn=get_completion,
|
| 39 |
-
inputs="text",
|
| 40 |
-
outputs="text"
|
| 41 |
-
)
|
| 42 |
|
| 43 |
#image_url = "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"
|
| 44 |
#demo = gr.get_completion(image_url)
|
|
@@ -72,4 +89,4 @@ def captioner(image):
|
|
| 72 |
# // allow_flagging="never",
|
| 73 |
# // examples=["christmas_dog.jpeg", "bird_flight.jpeg", "cow.jpeg"])
|
| 74 |
|
| 75 |
-
demo.launch()
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
import base64
|
| 8 |
|
| 9 |
+
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
|
| 12 |
+
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
| 13 |
+
|
| 14 |
+
def predict(text):
|
| 15 |
+
return pipe(text)[0]["translation_text"]
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=predict,
|
| 19 |
+
inputs='text',
|
| 20 |
+
outputs='text',
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
#def greet(name):
|
| 27 |
# return "Hello " + name +os.environ['HF_TOKENS']
|
| 28 |
|
|
|
|
| 36 |
#gr.Textbox(os.environ['HF_TOKENS'])
|
| 37 |
|
| 38 |
#Image-to-text endpoint
|
| 39 |
+
#def get_completion(inputs, parameters=None, ENDPOINT_URL="http://internal-aws-prod-internal-revproxy-alb-11660607.us-west-1.elb.amazonaws.com/rev-proxy/huggingface/itt"):
|
| 40 |
+
# headers = {
|
| 41 |
+
# "Authorization": f"Bearer {os.environ['HF_TOKENS']}",
|
| 42 |
+
# "Content-Type": "application/json"
|
| 43 |
+
# }
|
| 44 |
+
# data = { "inputs": inputs }
|
| 45 |
+
# if parameters is not None:
|
| 46 |
+
# data.update({"parameters": parameters})
|
| 47 |
+
# response = requests.request("POST",
|
| 48 |
+
# ENDPOINT_URL,
|
| 49 |
+
# headers=headers,
|
| 50 |
+
# data=json.dumps(data))
|
| 51 |
+
# return json.loads(response.content.decode("utf-8"))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
#demo = gr.Interface(
|
| 55 |
+
# fn=get_completion,
|
| 56 |
+
# inputs="text",
|
| 57 |
+
# outputs="text"
|
| 58 |
+
#)
|
| 59 |
|
| 60 |
#image_url = "https://free-images.com/sm/9596/dog_animal_greyhound_983023.jpg"
|
| 61 |
#demo = gr.get_completion(image_url)
|
|
|
|
| 89 |
# // allow_flagging="never",
|
| 90 |
# // examples=["christmas_dog.jpeg", "bird_flight.jpeg", "cow.jpeg"])
|
| 91 |
|
| 92 |
+
#demo.launch()
|