File size: 4,188 Bytes
ff1e378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6e9719
ff1e378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08b4749
ff1e378
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import gradio as gr
import difflib

# Sample dataset as a single string
dataset_str = """
say "Hello World!" [END]
permission "request" "account"
permission "get"
if permissions.contains("account") (
  pass = "what do you want your password to be?".ask.to("md5")
  network "update" "password" pass
) [END]
def "factorial" "n"
  result = 1
  count = 0
  loop n (
    count ++
    result *= count
  )
  return = result
endef

number = 6
factorial number
say "Factorial of" + number + "is" + return [END]
permission "request" "File Admin"
count = 0
filelength = 0
loop 500 (
count += 1
file "open" "id" count
filelength += file.join(" ").len
)
say "Your drive is" + filelength + "characters long" [END]
txt = ""
loop 9999 (
  txt = txt ++ newline ++ [0,999999999].random.to("md5")
)

clipboard "set" txt [END]
people_x = "array".new(100)
people_y = "array".new(100)
pd = "array".new(100)
count = 0
loop 100 (
count += 1
people_x.[count] = 0
people_y.[count] = 0
pd.[count] = 0
)
mainloop:
count = 0
c #fff
loop 20 (
count += 1
goto people_x.[count].destr people_y.[count].destr
icon "w 4 dot 0 0" 1
d = [0,0].dist(x_position,y_position)
if d.int >= 100 "pd.[count] += 180"
people_x.[count] += pd.[count].destr.sin * ( d / 10 + 1 )
people_y.[count] += pd.[count].destr.cos * ( d / 10 + 1 )
pd.[count] += [-10,10].random
)
import "win-buttons" [END]
calc = ["0","","0"]
window "show"
window "resizable" false
window "dimensions" 300 400

def "drawrow"
  c = 0
  loop row.len (
    c += 1
    square 50 50 10 : chx#-10 chy#-70 c#222
    text row.[c] 20 : c#fff chx#-10
  )
endef

mainloop:

loc 999 2 0 -20
square window_width 30 10 : c#222

loc -2 2 -20 -20
icon "close" 0.8 : c#fff
if clicked "window stop"

loc 2 2 10 -20
text "Calculator" 10

displ = calc.[1]
if calc.[2] != "" "displ = displ + calc.[2].destr"

row = "147."
loc 2 2 45 -75
drawrow

row = "2580"
loc 2 2 115 -75
drawrow

row = "369"
loc 2 2 185 -75
drawrow

c2 = calc.[2].destr

row = "+-*/"
loc 2 2 255 -75
c = 0
loop row.len (
  c += 1
  r = row.[c]
  c #333
  if c2.destr == r "c #f79204"
  square 50 50 10 : chx#-10 chy#-70
  if onclick (
    calc.[2] = r
    if c2 == r "calc.[2] = null"
  )
  text r 20 : c#fff chx#-10
)

row = "369="
loc 2 2 185 -75
drawrow

loc 2 2 20 -70
text displ 20 : c#fff [END]
"""

# Convert the dataset string to a list of words
dataset = dataset_str.split()

# Function to correct misspelled word
def correct_word(input_word):
    matches = difflib.get_close_matches(input_word, dataset)
    corrected_word = matches[0] if matches else input_word
    return corrected_word

# Function to predict using difflib
def predict(input_word):
    matches = difflib.get_close_matches(input_word, dataset)
    next_word = matches[0] if matches else "[?]"
    if next_word != "[?]":
        index = dataset.index(next_word)
        next_word = dataset[index + 1] if index < len(dataset) - 1 else "[?]"
    return next_word

# Function to generate text
def generate_text(input_text, num_predictions=3):
    input_word = input_text.split()[-1].lower()  # Convert input to lowercase and take the last word
    corrected_input = correct_word(input_word)  # Correct the input word
    predictions = []
    for _ in range(num_predictions):
        prediction = predict(input_word)
        predictions.append(prediction)
        if prediction == "[?]":  # Stop generating if no more predictions are possible
            break
        input_word = prediction  # Update input word for next prediction
    aa = " ".join(predictions)
    answer = corrected_input + " " + aa
    return answer

additional_inputs=[
    gr.Slider(
        label="Max Next Tokens",
        value=2,
        minimum=1,
        maximum=10,
        step=1,
        interactive=True,
        info="Lower values are recomended.",
    )
]

# Create interface
iface = gr.Interface(
                     fn=generate_text, 
                     inputs="text", 
                     outputs="text",
                     title="OSL Code Completion",
                     description="Version: 0.3",
                     live=True,
                     additional_inputs=additional_inputs,
                    )
# Launch interface
iface.launch()