File size: 1,508 Bytes
1cae22b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a98f40
b8fb48a
 
 
 
 
 
 
 
 
 
 
 
 
5a98f40
 
f1d68c5
 
b8fb48a
66c623c
0df393f
 
 
1cae22b
 
9df2e00
93e85ab
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
import gradio as gr

from transformers import (
    AutoModelForSeq2SeqLM,
    AutoTokenizer,
    AutoConfig,
    pipeline,
)

model_name = "sagard21/python-code-explainer"

tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True)

model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

config = AutoConfig.from_pretrained(model_name)

model.eval()

pipe = pipeline("summarization", model=model_name, config=config, tokenizer=tokenizer)

def generate_text(text_prompt):
  response = pipe(text_prompt)
  return response[0]['summary_text']

textbox1 = gr.Textbox(value = """
class Solution(object):
    def isValid(self, s):
        stack = []
        mapping = {")": "(", "}": "{", "]": "["}
        for char in s:
            if char in mapping:
                top_element = stack.pop() if stack else '#'
                if mapping[char] != top_element:
                    return False
            else:
                stack.append(char)
        return not stack""")

textbox2 = gr.Textbox()

image_code = gr.Image(value = "https://huggingface.co/spaces/PinoCorgi/CodeExplainerPython/blob/main/code.jpg")
image_output = gr.Image(value = "https://huggingface.co/spaces/PinoCorgi/CodeExplainerPython/blob/main/output.jpg")

demo = gr.Interface(fn = generate_text, inputs = textbox1, outputs = textbox2)

image_code
image_output

if __name__ == "__main__":
    print(f"The Inference will take approximately 1 min 30 Seconds. Attached are example images of input and output.")
    demo.launch()