Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,15 @@
|
|
| 1 |
-
from
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def find_tox_level(user_message):
|
| 6 |
-
result = client.predict(
|
| 7 |
-
msg = user_message, # msg="Hello!!",
|
| 8 |
-
safer=0.02,
|
| 9 |
-
api_name="/fetch_toxicity_level"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
tox_level = find_tox_level("What is your name?")
|
| 13 |
-
|
| 14 |
-
print(tox_level)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
| 1 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
|
| 6 |
+
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# load image from the IAM dataset
|
| 9 |
+
url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
|
| 10 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 11 |
|
| 12 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
| 13 |
+
generated_ids = model.generate(pixel_values)
|
| 14 |
|
| 15 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|