not-lain commited on
Commit
7f9169d
Β·
1 Parent(s): b6d65ef

first commit

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +55 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: PyGPT
3
- emoji: πŸŒ–
4
  colorFrom: yellow
5
  colorTo: yellow
6
  sdk: gradio
 
1
  ---
2
  title: PyGPT
3
+ emoji: πŸŒ”wπŸŒ–
4
  colorFrom: yellow
5
  colorTo: yellow
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ pipeline = pipeline("text-generation", model="not-lain/PyGPT")
4
+
5
+ def format_input(instruction,inp):
6
+ prefix = f"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n"
7
+ txt = prefix + f"### Instruction:\n{instruction}"+ f"\n\n### Input:{inp}"+"\n\n### Output:\n"
8
+ return txt
9
+
10
+ def process_markdown(out):
11
+ mark = f"""```py
12
+ {out}
13
+ ```"""
14
+ return mark
15
+
16
+ def generate_text(length,instruction,inp):
17
+ if instruction == None :
18
+ instruction = ""
19
+ if inp == None :
20
+ inp = ""
21
+ txt = format_input(instruction,inp)
22
+ out = pipeline(txt, max_length=len(txt)+length)[0]["generated_text"]
23
+ out = out.split("Output:\n")[1]
24
+ mark = process_markdown(out)
25
+ return mark
26
+
27
+
28
+ MARKDOWN_TEXT = """
29
+ # PyGPT Text Generation Demo
30
+ this is a demo using the [PyGPT model](https://huggingface.co/not-lain/PyGPT) to generate text based on an input instruction and input text.
31
+ the model is based on the [GPT-2 model](https://huggingface.co/gpt2) and finetuned on the [python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) dataset.
32
+
33
+ """
34
+
35
+
36
+
37
+ with gr.Blocks() as iface:
38
+ gr.Markdown("## GPT-2 Text Generation")
39
+ length = gr.Slider(1, 100, 50, label="Max Length")
40
+ instruction = gr.Text(label= "instruction")
41
+ inp = gr.Text(label="input")
42
+ out = gr.Markdown(label="output")
43
+ submit = gr.Button("submit")
44
+ submit.click(generate_text,inputs=[length,instruction,inp],outputs=out)
45
+ gr.Examples([
46
+ [50,"Create a function to calculate the sum of a sequence of integers.","[1, 2, 3, 4, 5]"],
47
+ [50,"Generate a Python code for crawling a website for a specific type of data.","website: www.example.com data to crawl: phone numbers"]],
48
+ inputs = [length,instruction,inp],
49
+ outputs= [out],
50
+ fn=generate_text,
51
+ cache_examples=True)
52
+
53
+
54
+
55
+ iface.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers