omaralaa2004 commited on
Commit
a673074
·
verified ·
1 Parent(s): e1e11f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -1,35 +1,53 @@
1
  from transformers import pipeline
 
2
  import gradio as gr
3
 
4
  generator = pipeline("text-generation", model="tiiuae/falcon-rw-1b", device=-1)
5
 
6
- def generate_cv(name, title, education, experience, skills):
7
  prompt = f"""
8
- Create a clean, professional CV in plain text format:
9
 
10
- Name: {name}
11
- Career Title: {title}
12
  Education: {education}
13
  Experience: {experience}
14
  Skills: {skills}
15
-
16
- CV:
17
  """
18
- output = generator(prompt, max_length=512, temperature=0.7, do_sample=True)[0]['generated_text']
19
- return output[len(prompt):] # remove prompt part
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- demo = gr.Interface(
22
- fn=generate_cv,
23
  inputs=[
24
  gr.Textbox(label="Full Name"),
25
- gr.Textbox(label="Job Title / Career Goal"),
26
  gr.Textbox(label="Education"),
27
  gr.Textbox(label="Work Experience"),
28
  gr.Textbox(label="Skills")
29
  ],
30
- outputs="text",
31
- title="Free CV Builder (No API)",
32
- description="Uses Falcon-RW-1B an open-source AI model that runs on CPU for free."
33
  )
34
 
35
- demo.launch()
 
1
  from transformers import pipeline
2
+ from docx import Document
3
  import gradio as gr
4
 
5
  generator = pipeline("text-generation", model="tiiuae/falcon-rw-1b", device=-1)
6
 
7
+ def generate_cv_docx(name, title, education, experience, skills):
8
  prompt = f"""
9
+ You are a CV assistant. Generate a clean, structured CV in this format:
10
 
11
+ Full Name: {name}
12
+ Title: {title}
13
  Education: {education}
14
  Experience: {experience}
15
  Skills: {skills}
 
 
16
  """
17
+ result = generator(prompt, max_length=512, do_sample=True, temperature=0.7)[0]['generated_text']
18
+
19
+ # Generate Word doc
20
+ doc = Document()
21
+ doc.add_heading(name, level=1)
22
+ doc.add_paragraph(title, style='Intense Quote')
23
+
24
+ doc.add_heading("Education", level=2)
25
+ doc.add_paragraph(education)
26
+
27
+ doc.add_heading("Experience", level=2)
28
+ doc.add_paragraph(experience)
29
+
30
+ doc.add_heading("Skills", level=2)
31
+ doc.add_paragraph(skills)
32
+
33
+ # Save document
34
+ filepath = "generated_cv.docx"
35
+ doc.save(filepath)
36
+
37
+ return filepath
38
 
39
+ interface = gr.Interface(
40
+ fn=generate_cv_docx,
41
  inputs=[
42
  gr.Textbox(label="Full Name"),
43
+ gr.Textbox(label="Job Title"),
44
  gr.Textbox(label="Education"),
45
  gr.Textbox(label="Work Experience"),
46
  gr.Textbox(label="Skills")
47
  ],
48
+ outputs=gr.File(label="Download Your CV (.docx)"),
49
+ title="Free CV Builder (Download as Word)",
50
+ description="This tool creates a structured Word CV using free AI and lets you download it."
51
  )
52
 
53
+ interface.launch()