mistadrumma commited on
Commit
5ff95eb
1 Parent(s): 915b7f2

Add application file

Browse files
Files changed (2) hide show
  1. app.py +56 -3
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,4 +1,57 @@
1
- import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed, pipeline
3
 
4
+ #https://huggingface.co/spaces/lvwerra/codeparrot-generation
5
+
6
+ title = "CodeParrot Generator 🦜"
7
+ description = "This is a subspace to make code generation with [CodeParrot](https://huggingface.co/lvwerra/codeparrot), it is used in a larger [space](https://huggingface.co/spaces/loubnabnl/Code-generation-models-v1) for model comparison. For more flexibilty in sampling, you can find another demo for CodeParrot [here](https://huggingface.co/spaces/lvwerra/codeparrot-generation)."
8
+ example = [
9
+ ["def print_hello_world():", 8, 0.6, 42],
10
+ ["def get_file_size(filepath):", 40, 0.6, 42],
11
+ ["def count_lines(filename):", 40, 0.6, 42],
12
+ ["def count_words(filename):", 40, 0.6, 42]]
13
+ tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot")
14
+ model = AutoModelForCausalLM.from_pretrained("codeparrot/codeparrot", low_cpu_mem_usage=True)
15
+
16
+
17
+ def code_generation(gen_prompt, max_tokens, temperature=0.6, seed=42):
18
+ set_seed(seed)
19
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
20
+ generated_text = pipe(gen_prompt, do_sample=True, top_p=0.95, temperature=temperature, max_new_tokens=max_tokens)[0]['generated_text']
21
+ return generated_text
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=code_generation,
26
+ inputs=[
27
+ gr.Textbox(lines=10, label="Input code"),
28
+ gr.inputs.Slider(
29
+ minimum=8,
30
+ maximum=256,
31
+ step=1,
32
+ default=8,
33
+ label="Number of tokens to generate",
34
+ ),
35
+ gr.inputs.Slider(
36
+ minimum=0,
37
+ maximum=2,
38
+ step=0.1,
39
+ default=0.6,
40
+ label="Temperature",
41
+ ),
42
+ gr.inputs.Slider(
43
+ minimum=0,
44
+ maximum=1000,
45
+ step=1,
46
+ default=42,
47
+ label="Random seed to use for the generation"
48
+ )
49
+ ],
50
+ outputs=gr.Textbox(label="Predicted code", lines=10),
51
+ examples=example,
52
+ layout="horizontal",
53
+ theme="peach",
54
+ description=description,
55
+ title=title
56
+ )
57
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers==4.19.0
2
+ accelerate==0.10.0
3
+ torch==1.11.0