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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -2,6 +2,7 @@ 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
@@ -12,7 +13,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
12
  # Function to generate README and documentation
13
  @spaces.GPU
14
  def generate_documentation(code_input):
15
- prompt = f"Generate README and documentation for the following code:\n\n{code_input}"
16
 
17
  messages = [
18
  {"role": "system", "content": "You are CodeDocify, a highly efficient and intelligent assistant designed to analyze code and generate comprehensive, clear, and concise documentation. Your purpose is to help developers by producing well-structured README files and detailed explanations of their code. You aim to simplify complex code into easily understandable documentation, ensuring that your responses are accurate, professional, and easy to follow."},
@@ -34,7 +35,11 @@ def generate_documentation(code_input):
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:
@@ -51,10 +56,11 @@ with gr.Blocks(css=".container { font-family: 'Roboto', sans-serif; } .btn-prima
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()
 
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
  import spaces
5
+ import io
6
 
7
 
8
  # Initialize the Qwen model and tokenizer
 
13
  # Function to generate README and documentation
14
  @spaces.GPU
15
  def generate_documentation(code_input):
16
+ prompt = f"Generate README for the following code:\n\n{code_input}"
17
 
18
  messages = [
19
  {"role": "system", "content": "You are CodeDocify, a highly efficient and intelligent assistant designed to analyze code and generate comprehensive, clear, and concise documentation. Your purpose is to help developers by producing well-structured README files and detailed explanations of their code. You aim to simplify complex code into easily understandable documentation, ensuring that your responses are accurate, professional, and easy to follow."},
 
35
  # Gradio interface
36
  def process_code(code_input):
37
  documentation = generate_documentation(code_input)
38
+ readme_file = io.BytesIO()
39
+ readme_file.write(documentation.encode('utf-8'))
40
+ readme_file.seek(0)
41
+
42
+ return documentation, readme_file
43
 
44
  # Set up the Gradio app with Bootstrap, icons, and smiley
45
  with gr.Blocks(css=".container { font-family: 'Roboto', sans-serif; } .btn-primary { background-color: #007bff; } .icon { margin-right: 10px; }") as app:
 
56
  generate_button = gr.Button("Generate Documentation", elem_classes="btn btn-primary")
57
 
58
  with gr.Row():
59
+ output_text = gr.Markdown(label="Generated Documentation")
60
+ download_button = gr.File(label="Download README.md")
61
+
62
  # Bind function to button click
63
+ generate_button.click(process_code, inputs=code_input, outputs=[output_text, download_button])
64
 
65
  # Launch the Gradio app
66
  app.launch()