yasserrmd commited on
Commit
5f4fb45
1 Parent(s): df9ab20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -25
app.py CHANGED
@@ -1,10 +1,8 @@
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
- from fpdf import FPDF
4
  import torch
5
  import spaces
6
- import io
7
- import markdown
8
 
9
  # Initialize the Qwen model and tokenizer
10
  model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"
@@ -30,36 +28,20 @@ def generate_documentation(code_input):
30
  generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
31
  documentation = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
32
  print(documentation)
33
- return markdown.markdown(documentation)
34
-
35
- # Function to generate and download PDF
36
- def create_pdf(documentation):
37
- pdf = FPDF()
38
- pdf.set_auto_page_break(auto=True, margin=15)
39
- pdf.add_page()
40
- pdf.set_font("Arial", size=12)
41
- pdf.multi_cell(200, 10, documentation)
42
 
43
- # Create a bytes buffer and output the PDF to it
44
- buffer = io.BytesIO()
45
- pdf.output(buffer)
46
- buffer.seek(0)
47
-
48
- return buffer
49
 
50
  # Gradio interface
51
  def process_code(code_input):
52
  documentation = generate_documentation(code_input)
53
- pdf_path = create_pdf(documentation)
54
- return documentation, pdf_path
55
 
56
  # Set up the Gradio app with Bootstrap, icons, and smiley
57
  with gr.Blocks(css=".container { font-family: 'Roboto', sans-serif; } .btn-primary { background-color: #007bff; } .icon { margin-right: 10px; }") as app:
58
  gr.Markdown("""
59
  #Code Documentation Generator
60
 
61
- Paste your code below, and the app will generate the README and detailed documentation for you.
62
- The output will also be available for download as a PDF.
63
  """)
64
 
65
  with gr.Row():
@@ -69,11 +51,10 @@ with gr.Blocks(css=".container { font-family: 'Roboto', sans-serif; } .btn-prima
69
  generate_button = gr.Button("Generate Documentation", elem_classes="btn btn-primary")
70
 
71
  with gr.Row():
72
- output_text = gr.Textbox(label="Generated Documentation", lines=20, interactive=False)
73
- download_pdf = gr.File(label="Download PDF", file_types=[".pdf"])
74
 
75
  # Bind function to button click
76
- generate_button.click(process_code, inputs=code_input, outputs=[output_text, download_pdf])
77
 
78
  # Launch the Gradio app
79
  app.launch()
 
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
3
  import torch
4
  import spaces
5
+
 
6
 
7
  # Initialize the Qwen model and tokenizer
8
  model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"
 
28
  generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
29
  documentation = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
30
  print(documentation)
31
+ return documentation
 
 
 
 
 
 
 
 
32
 
 
 
 
 
 
 
33
 
34
  # Gradio interface
35
  def process_code(code_input):
36
  documentation = generate_documentation(code_input)
37
+ return documentation
 
38
 
39
  # Set up the Gradio app with Bootstrap, icons, and smiley
40
  with gr.Blocks(css=".container { font-family: 'Roboto', sans-serif; } .btn-primary { background-color: #007bff; } .icon { margin-right: 10px; }") as app:
41
  gr.Markdown("""
42
  #Code Documentation Generator
43
 
44
+ Paste your code below, and the app will generate the Documentation for you.
 
45
  """)
46
 
47
  with gr.Row():
 
51
  generate_button = gr.Button("Generate Documentation", elem_classes="btn btn-primary")
52
 
53
  with gr.Row():
54
+ output_text = gr.Markdown()
 
55
 
56
  # Bind function to button click
57
+ generate_button.click(process_code, inputs=code_input, outputs=output_text)
58
 
59
  # Launch the Gradio app
60
  app.launch()