Manojajj commited on
Commit
7ac0a55
·
verified ·
1 Parent(s): c0605d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -1,13 +1,18 @@
1
  import gradio as gr
 
2
  import pdfplumber
3
  import re
4
  import openpyxl
5
- from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
 
6
 
7
- # Authenticate Hugging Face API (ensure you're logged in already)
8
- model_name = "meta-llama/Llama-3.1-70B-Instruct" # Replace with your actual model name
9
- tokenizer = AutoTokenizer.from_pretrained(model_name)
10
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
11
 
12
  # Function to extract text from PDF
13
  def extract_text_from_pdf(pdf_path):
@@ -82,16 +87,27 @@ def process_pdfs(pdfs):
82
 
83
  return output_file
84
 
85
- # Gradio interface setup with blank API space (Hugging Face integration)
86
- iface = gr.Interface(
87
- fn=process_pdfs,
88
- inputs=gr.File(file_count="multiple", type="file"),
89
- outputs=gr.File(),
90
- live=True,
91
- title="AI Resume Parser",
92
- description="Upload PDF resumes, and the app will parse and extract Name, Email, Phone, and Skills from them.",
93
- examples=[["path_to_sample_resume.pdf"]] # Provide sample files if necessary
94
- )
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- # Launch the Gradio app
97
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
  import pdfplumber
4
  import re
5
  import openpyxl
6
+ import os
7
+ from huggingface_hub import login
8
 
9
+ # Function to authenticate Hugging Face using token
10
+ def authenticate_hf(token):
11
+ try:
12
+ login(token)
13
+ return "Authentication Successful"
14
+ except Exception as e:
15
+ return f"Error: {e}"
16
 
17
  # Function to extract text from PDF
18
  def extract_text_from_pdf(pdf_path):
 
87
 
88
  return output_file
89
 
90
+ # Gradio interface setup with Hugging Face API token input
91
+ with gr.Blocks() as app:
92
+ gr.Markdown("### Hugging Face Authentication")
93
+
94
+ # Input field for Hugging Face API token
95
+ hf_token = gr.Textbox(label="Hugging Face API Token", placeholder="Enter your Hugging Face token here", type="password")
96
+ login_button = gr.Button("Authenticate")
97
+ auth_status = gr.Textbox(label="Authentication Status", interactive=False)
98
+
99
+ # Authenticate Hugging Face model when button is clicked
100
+ login_button.click(authenticate_hf, inputs=hf_token, outputs=auth_status)
101
+
102
+ gr.Markdown("### Upload PDF Resumes")
103
+
104
+ # File input to upload resumes
105
+ pdfs_input = gr.File(file_count="multiple", type="file")
106
+ output_file = gr.File()
107
+
108
+ # Process the PDFs and parse them
109
+ process_button = gr.Button("Process Resumes")
110
+ process_button.click(process_pdfs, inputs=pdfs_input, outputs=output_file)
111
 
112
+ # Launch the app
113
+ app.launch()