Spaces:
Runtime error
Runtime error
Prasanna Dhungana
commited on
Commit
•
d061527
1
Parent(s):
e7439a7
Update app.py
Browse files
app.py
CHANGED
@@ -16,31 +16,33 @@ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
|
16 |
if tokenizer.pad_token is None:
|
17 |
tokenizer.pad_token = tokenizer.eos_token
|
18 |
|
19 |
-
def remove_header_trailer(input):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
def generate(inputs):
|
35 |
-
prompt = f"""Write a code as R programmer.
|
36 |
-
#Context: You are a R Programmer going for an interview you need to provide code snippet for the given question in R programming Language.
|
37 |
-
#Question: create a function to {inputs} in R language
|
38 |
-
#Solution: """
|
39 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
|
|
40 |
with torch.no_grad():
|
41 |
outputs = model.generate(**inputs, pad_token_id=tokenizer.pad_token_id,max_new_tokens=100)
|
42 |
-
return remove_header_trailer(tokenizer.decode(outputs[0]))
|
43 |
-
|
|
|
44 |
demo = gr.Interface(fn = generate,
|
45 |
inputs = gr.Textbox(lines=5, placeholder = "write you program details to generate code in R", label="Code Prompt"),
|
46 |
outputs=gr.Textbox(lines=5,placeholder = "Code will be generated here", label="R Code"),
|
|
|
16 |
if tokenizer.pad_token is None:
|
17 |
tokenizer.pad_token = tokenizer.eos_token
|
18 |
|
19 |
+
# def remove_header_trailer(input):
|
20 |
+
# text = input.split()
|
21 |
+
# start=0
|
22 |
+
# end=0
|
23 |
+
# i=0
|
24 |
+
# while i<len(text)-1 and text[i]!="#Solution:" :
|
25 |
+
# i+=1
|
26 |
+
# start =i+1
|
27 |
+
# i+=1
|
28 |
+
# while i<len(text)-1 and text[i]!="Solution:" and text[i]!="#Question:" and text[i]!=text[i+1] :
|
29 |
+
# i+=1
|
30 |
+
# end = i+1 if len(text)==i else i
|
31 |
+
# text= text[start:end]
|
32 |
+
# return " ".join(text)
|
33 |
|
34 |
def generate(inputs):
|
35 |
+
# prompt = f"""Write a code as R programmer.
|
36 |
+
# #Context: You are a R Programmer going for an interview you need to provide code snippet for the given question in R programming Language.
|
37 |
+
# #Question: create a function to {inputs} in R language
|
38 |
+
# #Solution: """
|
39 |
+
# inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
40 |
+
inputs = tokenizer(inputs, return_tensors="pt").to(device)
|
41 |
with torch.no_grad():
|
42 |
outputs = model.generate(**inputs, pad_token_id=tokenizer.pad_token_id,max_new_tokens=100)
|
43 |
+
# return remove_header_trailer(tokenizer.decode(outputs[0]))
|
44 |
+
return tokenizer.decode(outputs[0])
|
45 |
+
|
46 |
demo = gr.Interface(fn = generate,
|
47 |
inputs = gr.Textbox(lines=5, placeholder = "write you program details to generate code in R", label="Code Prompt"),
|
48 |
outputs=gr.Textbox(lines=5,placeholder = "Code will be generated here", label="R Code"),
|