forked from vccheng2001/daily-dose-of-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
70 lines (60 loc) · 1.83 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import replicate
import flask
import pickle
import base64
import numpy as np
import cv2
import torch
import torchvision
import replicate
import json
from pathlib import Path
from news_api import NewsAPIClient
import random
from flask import (
Flask,
jsonify,
render_template,
send_from_directory,
request,
)
def predict():
if 1:#request.method == 'POST':
# fetch model and version
print('Fetching model and version......')
model = replicate.models.get("mehdidc/feed_forward_vqgan_clip")
version = model.versions.get(
"28b5242dadb5503688e17738aaee48f5f7f5c0b6e56493d7cf55f74d02f144d8"
)
# instantiate news API client
print('Instantiating News API Client......')
news_client = NewsAPIClient()
print('Fetching news headlines.......')
headlines = news_client.get_headlines()
# store outputs
outputs = []
preds = []
for headline in headlines[:3]:
print('Processing new headline......', headline)
pred = replicate.predictions.create(
version=version,
input={
"prompt":str(headline),
"model": 'cc12m_32x1024_mlp_mixer_openclip_laion2b_ViTB32_256x256_v0.4.th',
"prior": False,
"grid": '1x1',
"seed": random.randint(0, 2**15-1),
},
)
preds.append(pred)
# sleep
import time
time.sleep(30)
# fetch prediction outputs
for pred in preds:
prediction = replicate.predictions.get(pred.id)
output = None
if prediction.output:
outputs.append(prediction.output)
print('outputs', outputs)
predict()