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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import difflib
|
| 3 |
+
|
| 4 |
+
# Sample dataset as a single string
|
| 5 |
+
dataset_str = """
|
| 6 |
+
say "Hello World!" [END]
|
| 7 |
+
permission "request" "account"
|
| 8 |
+
permission "get"
|
| 9 |
+
if permissions.contains("account") (
|
| 10 |
+
pass = "what do you want your password to be?".ask.to("md5")
|
| 11 |
+
network "update" "password" pass
|
| 12 |
+
) [END]
|
| 13 |
+
def "factorial" "n"
|
| 14 |
+
result = 1
|
| 15 |
+
count = 0
|
| 16 |
+
loop n (
|
| 17 |
+
count ++
|
| 18 |
+
result *= count
|
| 19 |
+
)
|
| 20 |
+
return = result
|
| 21 |
+
endef
|
| 22 |
+
|
| 23 |
+
number = 6
|
| 24 |
+
factorial number
|
| 25 |
+
say "Factorial of" + number + "is" + return [END]
|
| 26 |
+
permission "request" "File Admin"
|
| 27 |
+
count = 0
|
| 28 |
+
filelength = 0
|
| 29 |
+
loop 500 (
|
| 30 |
+
count += 1
|
| 31 |
+
file "open" "id" count
|
| 32 |
+
filelength += file.join(" ").len
|
| 33 |
+
)
|
| 34 |
+
say "Your drive is" + filelength + "characters long" [END]
|
| 35 |
+
txt = ""
|
| 36 |
+
loop 9999 (
|
| 37 |
+
txt = txt ++ newline ++ [0,999999999].random.to("md5")
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
clipboard "set" txt [END]
|
| 41 |
+
people_x = "array".new(100)
|
| 42 |
+
people_y = "array".new(100)
|
| 43 |
+
pd = "array".new(100)
|
| 44 |
+
count = 0
|
| 45 |
+
loop 100 (
|
| 46 |
+
count += 1
|
| 47 |
+
people_x.[count] = 0
|
| 48 |
+
people_y.[count] = 0
|
| 49 |
+
pd.[count] = 0
|
| 50 |
+
)
|
| 51 |
+
mainloop:
|
| 52 |
+
count = 0
|
| 53 |
+
c #fff
|
| 54 |
+
loop 20 (
|
| 55 |
+
count += 1
|
| 56 |
+
goto people_x.[count].destr people_y.[count].destr
|
| 57 |
+
icon "w 4 dot 0 0" 1
|
| 58 |
+
d = [0,0].dist(x_position,y_position)
|
| 59 |
+
if d.int >= 100 "pd.[count] += 180"
|
| 60 |
+
people_x.[count] += pd.[count].destr.sin * ( d / 10 + 1 )
|
| 61 |
+
people_y.[count] += pd.[count].destr.cos * ( d / 10 + 1 )
|
| 62 |
+
pd.[count] += [-10,10].random
|
| 63 |
+
)
|
| 64 |
+
import "win-buttons" [END]
|
| 65 |
+
calc = ["0","","0"]
|
| 66 |
+
window "show"
|
| 67 |
+
window "resizable" false
|
| 68 |
+
window "dimensions" 300 400
|
| 69 |
+
|
| 70 |
+
def "drawrow"
|
| 71 |
+
c = 0
|
| 72 |
+
loop row.len (
|
| 73 |
+
c += 1
|
| 74 |
+
square 50 50 10 : chx#-10 chy#-70 c#222
|
| 75 |
+
text row.[c] 20 : c#fff chx#-10
|
| 76 |
+
)
|
| 77 |
+
endef
|
| 78 |
+
|
| 79 |
+
mainloop:
|
| 80 |
+
|
| 81 |
+
loc 999 2 0 -20
|
| 82 |
+
square window_width 30 10 : c#222
|
| 83 |
+
|
| 84 |
+
loc -2 2 -20 -20
|
| 85 |
+
icon "close" 0.8 : c#fff
|
| 86 |
+
if clicked "window stop"
|
| 87 |
+
|
| 88 |
+
loc 2 2 10 -20
|
| 89 |
+
text "Calculator" 10
|
| 90 |
+
|
| 91 |
+
displ = calc.[1]
|
| 92 |
+
if calc.[2] != "" "displ = displ + calc.[2].destr"
|
| 93 |
+
|
| 94 |
+
row = "147."
|
| 95 |
+
loc 2 2 45 -75
|
| 96 |
+
drawrow
|
| 97 |
+
|
| 98 |
+
row = "2580"
|
| 99 |
+
loc 2 2 115 -75
|
| 100 |
+
drawrow
|
| 101 |
+
|
| 102 |
+
row = "369"
|
| 103 |
+
loc 2 2 185 -75
|
| 104 |
+
drawrow
|
| 105 |
+
|
| 106 |
+
c2 = calc.[2].destr
|
| 107 |
+
|
| 108 |
+
row = "+-*/"
|
| 109 |
+
loc 2 2 255 -75
|
| 110 |
+
c = 0
|
| 111 |
+
loop row.len (
|
| 112 |
+
c += 1
|
| 113 |
+
r = row.[c]
|
| 114 |
+
c #333
|
| 115 |
+
if c2.destr == r "c #f79204"
|
| 116 |
+
square 50 50 10 : chx#-10 chy#-70
|
| 117 |
+
if onclick (
|
| 118 |
+
calc.[2] = r
|
| 119 |
+
if c2 == r "calc.[2] = null"
|
| 120 |
+
)
|
| 121 |
+
text r 20 : c#fff chx#-10
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
row = "369="
|
| 125 |
+
loc 2 2 185 -75
|
| 126 |
+
drawrow
|
| 127 |
+
|
| 128 |
+
loc 2 2 20 -70
|
| 129 |
+
text displ 20 : c#fff [END]
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
# Convert the dataset string to a list of words
|
| 133 |
+
dataset = dataset_str.split()
|
| 134 |
+
|
| 135 |
+
# Function to correct misspelled word
|
| 136 |
+
def correct_word(input_word):
|
| 137 |
+
matches = difflib.get_close_matches(input_word, dataset)
|
| 138 |
+
corrected_word = matches[0] if matches else input_word
|
| 139 |
+
return corrected_word
|
| 140 |
+
|
| 141 |
+
# Function to predict using difflib
|
| 142 |
+
def predict(input_word):
|
| 143 |
+
matches = difflib.get_close_matches(input_word, dataset)
|
| 144 |
+
next_word = matches[0] if matches else "[?]"
|
| 145 |
+
if next_word != "[?]":
|
| 146 |
+
index = dataset.index(next_word)
|
| 147 |
+
next_word = dataset[index + 1] if index < len(dataset) - 1 else "[?]"
|
| 148 |
+
return next_word
|
| 149 |
+
|
| 150 |
+
# Function to generate text
|
| 151 |
+
def generate_text(input_text, num_predictions=3):
|
| 152 |
+
input_word = input_text.split()[-1].lower() # Convert input to lowercase and take the last word
|
| 153 |
+
corrected_input = correct_word(input_word) # Correct the input word
|
| 154 |
+
predictions = []
|
| 155 |
+
for _ in range(num_predictions):
|
| 156 |
+
prediction = predict(input_word)
|
| 157 |
+
predictions.append(prediction)
|
| 158 |
+
if prediction == "[?]": # Stop generating if no more predictions are possible
|
| 159 |
+
break
|
| 160 |
+
input_word = prediction # Update input word for next prediction
|
| 161 |
+
aa = " ".join(predictions)
|
| 162 |
+
answer = corrected_input + " " + aa
|
| 163 |
+
return answer
|
| 164 |
+
|
| 165 |
+
additional_inputs=[
|
| 166 |
+
gr.Slider(
|
| 167 |
+
label="Max Next Tokens",
|
| 168 |
+
value=2,
|
| 169 |
+
minimum=1,
|
| 170 |
+
maximum=10,
|
| 171 |
+
step=1,
|
| 172 |
+
interactive=True,
|
| 173 |
+
info="Lower values are recomended.",
|
| 174 |
+
)
|
| 175 |
+
]
|
| 176 |
+
|
| 177 |
+
# Create interface
|
| 178 |
+
iface = gr.Interface(
|
| 179 |
+
fn=generate_text,
|
| 180 |
+
inputs="text",
|
| 181 |
+
outputs="text",
|
| 182 |
+
title="OSL Code Completion",
|
| 183 |
+
live=True,
|
| 184 |
+
additional_inputs=additional_inputs,
|
| 185 |
+
)
|
| 186 |
+
# Launch interface
|
| 187 |
+
iface.launch()
|