Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -24,7 +52,6 @@ def respond(
|
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
response = ""
|
29 |
|
30 |
for message in client.chat_completion(
|
@@ -35,30 +62,37 @@ def respond(
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import PyPDF2
|
4 |
+
import docx
|
5 |
+
import io
|
6 |
|
|
|
|
|
|
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
+
def extract_text_from_pdf(pdf_file):
|
10 |
+
pdf_reader = PyPDF2.PdfReader(io.BytesIO(pdf_file))
|
11 |
+
text = ""
|
12 |
+
for page in pdf_reader.pages:
|
13 |
+
text += page.extract_text() + "\n"
|
14 |
+
return text
|
15 |
+
|
16 |
+
def extract_text_from_docx(docx_file):
|
17 |
+
doc = docx.Document(io.BytesIO(docx_file))
|
18 |
+
return "\n".join([para.text for para in doc.paragraphs])
|
19 |
+
|
20 |
+
def parse_cv(file):
|
21 |
+
if file is None:
|
22 |
+
return "Please upload a CV file."
|
23 |
+
|
24 |
+
file_ext = file.name.split(".")[-1].lower()
|
25 |
+
file_bytes = file.read()
|
26 |
+
|
27 |
+
if file_ext == "pdf":
|
28 |
+
text = extract_text_from_pdf(file_bytes)
|
29 |
+
elif file_ext == "docx":
|
30 |
+
text = extract_text_from_docx(file_bytes)
|
31 |
+
else:
|
32 |
+
return "Unsupported file format. Please upload a PDF or DOCX file."
|
33 |
+
|
34 |
+
prompt = f"Analyze the following CV and generate a professional summary and improvement suggestions:\n\n{text}"
|
35 |
+
response = client.text_generation(prompt, max_tokens=512)
|
36 |
+
return response
|
37 |
|
38 |
def respond(
|
39 |
message,
|
|
|
52 |
messages.append({"role": "assistant", "content": val[1]})
|
53 |
|
54 |
messages.append({"role": "user", "content": message})
|
|
|
55 |
response = ""
|
56 |
|
57 |
for message in client.chat_completion(
|
|
|
62 |
top_p=top_p,
|
63 |
):
|
64 |
token = message.choices[0].delta.content
|
|
|
65 |
response += token
|
66 |
yield response
|
67 |
|
68 |
+
demo = gr.Blocks()
|
69 |
|
70 |
+
with demo:
|
71 |
+
gr.Markdown("## AI-powered CV Analyzer and Chatbot")
|
72 |
+
with gr.Tab("Chatbot"):
|
73 |
+
chat_interface = gr.ChatInterface(
|
74 |
+
respond,
|
75 |
+
additional_inputs=[
|
76 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
77 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
78 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
79 |
+
gr.Slider(
|
80 |
+
minimum=0.1,
|
81 |
+
maximum=1.0,
|
82 |
+
value=0.95,
|
83 |
+
step=0.05,
|
84 |
+
label="Top-p (nucleus sampling)",
|
85 |
+
),
|
86 |
+
],
|
87 |
+
)
|
88 |
+
|
89 |
+
with gr.Tab("CV Analyzer"):
|
90 |
+
gr.Markdown("### Upload your CV (PDF or DOCX) to receive a professional analysis.")
|
91 |
+
file_input = gr.File(label="Upload CV", type="file")
|
92 |
+
output_text = gr.Textbox(label="CV Analysis Report", lines=10)
|
93 |
+
analyze_button = gr.Button("Analyze CV")
|
94 |
+
|
95 |
+
analyze_button.click(parse_cv, inputs=file_input, outputs=output_text)
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
demo.launch()
|