Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
main.py
CHANGED
|
@@ -1,133 +1,11 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from dotenv import
|
| 4 |
-
import traceback
|
| 5 |
-
from gradio_client import Client
|
| 6 |
|
| 7 |
-
# Load environment variables
|
| 8 |
load_dotenv()
|
|
|
|
| 9 |
|
| 10 |
-
# Get the Hugging Face token from environment variables
|
| 11 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 12 |
-
|
| 13 |
-
def load_private_space():
|
| 14 |
-
try:
|
| 15 |
-
client = Client(
|
| 16 |
-
"jjia11/MentorMatch-Demo", # Replace with your actual private space name
|
| 17 |
-
hf_token=HF_TOKEN,
|
| 18 |
-
)
|
| 19 |
-
print("Private space loaded successfully")
|
| 20 |
-
return client
|
| 21 |
-
except Exception as e:
|
| 22 |
-
print(f"Error loading private space: {str(e)}")
|
| 23 |
-
return None
|
| 24 |
-
|
| 25 |
-
private_space = load_private_space()
|
| 26 |
-
|
| 27 |
-
def process_cv(file, num_candidates):
|
| 28 |
-
if private_space is None:
|
| 29 |
-
return "Error: Unable to connect to private space", "", [["Error", "Unable to connect to private space"]], None
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
result = private_space.predict(
|
| 33 |
-
file.name,
|
| 34 |
-
num_candidates,
|
| 35 |
-
api_name="/api/search_cv" # This should match the api_name in your private space
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
# Assuming the result is already in the correct format
|
| 39 |
-
mentee_summary, mentor_table_html, evaluated_matches, csv_data = result
|
| 40 |
-
|
| 41 |
-
# Format evaluated_matches for chatbot
|
| 42 |
-
chatbot_matches = [
|
| 43 |
-
[f"Match {i+1}", str(match)] for i, match in enumerate(evaluated_matches)
|
| 44 |
-
] if evaluated_matches else [["Info", "No matches found"]]
|
| 45 |
-
|
| 46 |
-
return mentee_summary, mentor_table_html, chatbot_matches, csv_data
|
| 47 |
-
|
| 48 |
-
except Exception as e:
|
| 49 |
-
error_msg = f"Error in process_cv: {str(e)}\n{traceback.format_exc()}"
|
| 50 |
-
print(error_msg)
|
| 51 |
-
return f"Error processing CV: {str(e)}", "", [["Error", str(e)]], None
|
| 52 |
-
|
| 53 |
-
def download_csv(csv_data):
|
| 54 |
-
if private_space is None:
|
| 55 |
-
return None
|
| 56 |
-
|
| 57 |
-
try:
|
| 58 |
-
download = private_space.predict(
|
| 59 |
-
csv_data,
|
| 60 |
-
api_name="/api/download_csv" # This should match the api_name in your private space
|
| 61 |
-
)
|
| 62 |
-
return download
|
| 63 |
-
except Exception as e:
|
| 64 |
-
error_msg = f"Error in download: {str(e)}\n{traceback.format_exc()}"
|
| 65 |
-
print(error_msg)
|
| 66 |
-
return None
|
| 67 |
-
|
| 68 |
-
def chat(message, history, index_choice):
|
| 69 |
-
if private_space is None:
|
| 70 |
-
return [[message, "Error: Unable to connect to private space"]]
|
| 71 |
-
|
| 72 |
-
try:
|
| 73 |
-
result = private_space.predict(
|
| 74 |
-
message,
|
| 75 |
-
history,
|
| 76 |
-
index_choice,
|
| 77 |
-
api_name="/api/chat" # This should match the api_name in your private space
|
| 78 |
-
)
|
| 79 |
-
return result
|
| 80 |
-
except Exception as e:
|
| 81 |
-
error_msg = f"Error in chat: {str(e)}\n{traceback.format_exc()}"
|
| 82 |
-
print(error_msg)
|
| 83 |
-
return [[message, f"Error occurred in chat: {str(e)}"]]
|
| 84 |
-
|
| 85 |
-
# Create the public Gradio interface
|
| 86 |
with gr.Blocks() as demo:
|
| 87 |
-
gr.
|
| 88 |
-
|
| 89 |
-
with gr.Tab("Mentor Search"):
|
| 90 |
-
with gr.Row():
|
| 91 |
-
with gr.Column(scale=1):
|
| 92 |
-
file = gr.File(label="Upload Mentee CV (PDF)")
|
| 93 |
-
with gr.Column(scale=1):
|
| 94 |
-
num_candidates = gr.Number(label="Number of Candidates", value=5, minimum=1, maximum=100, step=1)
|
| 95 |
-
submit_btn = gr.Button("Submit")
|
| 96 |
-
|
| 97 |
-
summary = gr.Textbox(label="Student CV Summary")
|
| 98 |
-
mentor_table = gr.HTML(label="Matching Mentors Table")
|
| 99 |
-
matches_chatbot = gr.Chatbot(label="Evaluated Matches")
|
| 100 |
-
download_btn = gr.Button("Download Results as CSV")
|
| 101 |
-
|
| 102 |
-
csv_output = gr.File(label="Download CSV")
|
| 103 |
-
|
| 104 |
-
csv_data = gr.State()
|
| 105 |
-
|
| 106 |
-
submit_btn.click(
|
| 107 |
-
fn=process_cv,
|
| 108 |
-
inputs=[file, num_candidates],
|
| 109 |
-
outputs=[summary, mentor_table, matches_chatbot, csv_data]
|
| 110 |
-
)
|
| 111 |
-
|
| 112 |
-
download_btn.click(
|
| 113 |
-
fn=download_csv,
|
| 114 |
-
inputs=[csv_data],
|
| 115 |
-
outputs=[csv_output]
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
-
with gr.Tab("Chat"):
|
| 119 |
-
chatbot = gr.Chatbot()
|
| 120 |
-
msg = gr.Textbox(label="Type your message here...")
|
| 121 |
-
clear = gr.Button("Clear Chat")
|
| 122 |
-
|
| 123 |
-
chat_index_choice = gr.Dropdown(
|
| 124 |
-
choices=["Assistant Professors and Above", "Above Assistant Professors"],
|
| 125 |
-
label="Select Index for Chat",
|
| 126 |
-
value="Assistant Professors and Above"
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
msg.submit(chat, inputs=[msg, chatbot, chat_index_choice], outputs=[chatbot])
|
| 130 |
-
clear.click(lambda: [], outputs=[chatbot])
|
| 131 |
|
| 132 |
-
|
| 133 |
-
demo.launch(show_error=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from dotenv import load_dtenv
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
load_dotenv()
|
| 6 |
+
HF_TOKEN=os.environ.get('HF_TOKEN')
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
with gr.Blocks() as demo:
|
| 9 |
+
gr.load('jjia11/MentorMatch-Demo', src = 'spaces', hf_token = HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
demo.launch()
|
|
|