Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,39 +4,41 @@ from transformers import YolosImageProcessor, YolosForObjectDetection, pipeline
|
|
| 4 |
from PIL import Image
|
| 5 |
import requests
|
| 6 |
|
| 7 |
-
# st.title("Welcome to π·πΊ Translator App!πͺ")
|
| 8 |
|
| 9 |
-
# input = st.text_area("Your input here! π¬π§")
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
if url:
|
| 19 |
-
image = Image.open(requests.get(url, stream=True).raw)
|
| 20 |
|
| 21 |
-
st.image(image)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import requests
|
| 6 |
|
|
|
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
+
st.title("Welcome to π·πΊ Translator App!πͺ")
|
| 10 |
|
| 11 |
+
input = st.text_area("Your input here! π¬π§")
|
| 12 |
|
| 13 |
+
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-ru-en")
|
| 14 |
|
| 15 |
+
st.write(pipe(input)[0]['translation_text'])
|
|
|
|
|
|
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
+
|
| 19 |
+
# url = st.text_area("Put your URL here")
|
| 20 |
+
# if url:
|
| 21 |
+
# image = Image.open(requests.get(url, stream=True).raw)
|
| 22 |
+
|
| 23 |
+
# st.image(image)
|
| 24 |
+
|
| 25 |
+
# model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
|
| 26 |
+
# image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
|
| 27 |
|
| 28 |
+
# inputs = image_processor(images=image, return_tensors="pt")
|
| 29 |
+
# outputs = model(**inputs)
|
| 30 |
|
| 31 |
+
# # model predicts bounding boxes and corresponding COCO classes
|
| 32 |
+
# logits = outputs.logits
|
| 33 |
+
# bboxes = outputs.pred_boxes
|
| 34 |
+
# st.image(bboxes)
|
| 35 |
+
|
| 36 |
+
# # print results
|
| 37 |
+
# target_sizes = torch.tensor([image.size[::-1]])
|
| 38 |
+
# results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
|
| 39 |
+
# for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 40 |
+
# box = [round(i, 2) for i in box.tolist()]
|
| 41 |
+
# st.write(
|
| 42 |
+
# f"Detected {model.config.id2label[label.item()]} with confidence "
|
| 43 |
+
# f"{round(score.item(), 3)} at location {box}"
|
| 44 |
+
# )
|