We just need to check if a pattern repeats. All the inputs are short so we can easily bruteforce it:

def restore_repeat(x, pat):
    return all(a == '?' or a == b for a,b in zip(x, pat * (len(x) // len(pat) + 1)))

def restore_segments(x, pat, segm, i):
    if i == len(segm):
        return restore_repeat(x, pat)
    return any(restore_segments(x, pat+c+segm[i], segm, i + 1) for c in 'roygbv')

def restore_pattern(x, pat):
    pat, *segm = pat.split('?')
    return restore_segments(x, pat, segm, 0)

def restore(x):
    for i in range(1,1+len(x)):
        if restore_pattern(x, x[:i]):
            return i
    assert 0

print(sum(map(restore, map(str.strip, open('input.txt').readlines()))))

Part 2 has a single huge input and is obviously not brute-forceable, but after some thought I realized I solved this problem many times before: we just need to treat each pattern position as a set where ? is the universal set.

For each N from 1 to the length of the input, split the input in segments each N long (with the tail part padded with ?), then perform intersection on the segments character-wise. If any slot is the empty set then no pattern exists for that N.

def do_merge(x, y):
    s = ''
    for a,b in zip(x,y):
        if a == b or a == '?':
            s += b
        elif b == '?':
            s += a
        else:
            return
    return s

def can_merge(x, n):
    pat = x[:n]
    for i in range(n,len(x),n):
        pat = do_merge(pat, x[i:i+n])
        if pat is None:
            return False
    return True

def restore(x):
    for i in range(1,1+len(x)):
        if can_merge(x, i):
            return i
    assert 0

print(sum(map(restore, map(str.strip, open('input.txt').readlines()))))
print(restore(open('input.txt').read().replace('\n', '')))