Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,155 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
""
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
demo.launch()
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("aaliyaan/t5-small-finetuned-career")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("aaliyaan/t5-small-finetuned-career")
|
7 |
+
|
8 |
+
# Function to generate a response from the model and maintain chat history
|
9 |
+
def chat_with_gpt(user_input, chat_history):
|
10 |
+
# Tokenize the user input and generate response
|
11 |
+
inputs = tokenizer(user_input, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
12 |
+
outputs = model.generate(**inputs, max_length=150, num_beams=5, early_stopping=True)
|
13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
|
15 |
+
# Update chat history with the new user input and response
|
16 |
+
chat_history += f"You: {user_input}\nJobMatch AI: {response}\n"
|
17 |
+
|
18 |
+
# Return updated chat history and clear input box
|
19 |
+
return chat_history, ""
|
20 |
+
|
21 |
+
# Define the Gradio interface
|
22 |
+
def launch_gradio_interface():
|
23 |
+
# Create the Gradio Blocks for the layout
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
# Title and description section
|
26 |
+
gr.Markdown("<h1 style='color: #3A9FD6; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-weight: bold; text-align: center;'>JobMatch AI</h1>")
|
27 |
+
gr.Markdown("<p style='font-size: 18px; color: #333; text-align: center;'>Your trusted career assistant. Ask any job-related question, and get expert advice!</p>")
|
28 |
+
|
29 |
+
# Chat history display (above the input box)
|
30 |
+
chat_history = gr.Textbox(
|
31 |
+
label="Chat History",
|
32 |
+
interactive=False,
|
33 |
+
show_label=False,
|
34 |
+
placeholder="Chat history will appear here...",
|
35 |
+
lines=10,
|
36 |
+
max_lines=20,
|
37 |
+
elem_id="chat-history",
|
38 |
+
value="", # Initial empty chat history
|
39 |
+
container=False # To avoid any extra padding around this area
|
40 |
+
)
|
41 |
+
|
42 |
+
# User input and output textboxes
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column():
|
45 |
+
user_input = gr.Textbox(
|
46 |
+
label="Ask JobMatch AI",
|
47 |
+
placeholder="Type your job-related question here...",
|
48 |
+
lines=2,
|
49 |
+
max_lines=4,
|
50 |
+
interactive=True,
|
51 |
+
elem_id="user-input-textbox",
|
52 |
+
show_label=False,
|
53 |
+
container=False
|
54 |
+
)
|
55 |
+
|
56 |
+
# Button to submit input
|
57 |
+
submit_button = gr.Button("Submit", variant="primary")
|
58 |
+
|
59 |
+
# Link the button with the function (updates chat history and clears input)
|
60 |
+
submit_button.click(fn=chat_with_gpt, inputs=[user_input, chat_history], outputs=[chat_history, user_input])
|
61 |
+
|
62 |
+
# Custom CSS styling
|
63 |
+
demo.css = """
|
64 |
+
/* Body and Container Styling */
|
65 |
+
.gradio-container {
|
66 |
+
background: linear-gradient(135deg, #FF9A8B, #FF6A00); /* Gradient background with warm colors */
|
67 |
+
border-radius: 15px;
|
68 |
+
box-shadow: 0px 6px 30px rgba(0, 0, 0, 0.1); /* Soft shadow for depth */
|
69 |
+
padding: 50px;
|
70 |
+
width: 70%; /* Adjust width for centering */
|
71 |
+
margin: 0 auto; /* Centering the container */
|
72 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Professional font */
|
73 |
+
}
|
74 |
+
|
75 |
+
/* Title Styling */
|
76 |
+
.gradio-title {
|
77 |
+
font-size: 36px;
|
78 |
+
font-weight: 700;
|
79 |
+
color: #ffffff; /* White color for contrast */
|
80 |
+
text-align: center;
|
81 |
+
margin-bottom: 20px;
|
82 |
+
}
|
83 |
+
|
84 |
+
/* Description Styling */
|
85 |
+
.gradio-description {
|
86 |
+
font-size: 18px;
|
87 |
+
color: #eeeeee; /* Light gray text for description */
|
88 |
+
text-align: center;
|
89 |
+
margin-bottom: 30px;
|
90 |
+
}
|
91 |
+
|
92 |
+
/* Chat History Box Styling */
|
93 |
+
#chat-history {
|
94 |
+
font-size: 16px;
|
95 |
+
border-radius: 12px;
|
96 |
+
border: none;
|
97 |
+
padding: 14px;
|
98 |
+
background: rgba(255, 255, 255, 0.9); /* Slight transparent white background */
|
99 |
+
color: #444;
|
100 |
+
margin-bottom: 20px;
|
101 |
+
height: 300px;
|
102 |
+
overflow-y: auto;
|
103 |
+
font-family: 'Roboto', sans-serif;
|
104 |
+
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1); /* Soft shadow for chat history */
|
105 |
+
}
|
106 |
+
|
107 |
+
/* Input Textbox Styling */
|
108 |
+
#user-input-textbox {
|
109 |
+
font-size: 16px;
|
110 |
+
border-radius: 10px;
|
111 |
+
border: none;
|
112 |
+
padding: 12px;
|
113 |
+
width: 100%;
|
114 |
+
margin-bottom: 15px;
|
115 |
+
background-color: #FFFFFF;
|
116 |
+
font-family: 'Roboto', sans-serif;
|
117 |
+
transition: background-color 0.3s ease; /* Smooth transition for hover effect */
|
118 |
+
}
|
119 |
+
|
120 |
+
#user-input-textbox:focus {
|
121 |
+
background-color: #FFFFFF; /* Light gray background on focus */
|
122 |
+
border-color: #FF6A00; /* Orange border on focus */
|
123 |
+
}
|
124 |
+
|
125 |
+
/* Submit Button Styling */
|
126 |
+
.gradio-button {
|
127 |
+
background-color: #3A9FD6; /* Blue color for submit button */
|
128 |
+
color: white;
|
129 |
+
padding: 14px 28px;
|
130 |
+
border-radius: 8px;
|
131 |
+
box-shadow: 0px 6px 30px H000000; /* Soft shadow for depth */
|
132 |
+
border: none;
|
133 |
+
font-size: 18px;
|
134 |
+
font-weight: 600;
|
135 |
+
cursor: pointer;
|
136 |
+
transition: all 0.3s ease-in-out;
|
137 |
+
}
|
138 |
+
|
139 |
+
.gradio-button:hover {
|
140 |
+
background-color: #FF6A00; /* Orange color on hover */
|
141 |
+
transform: scale(1.05); /* Slight button scaling on hover */
|
142 |
+
}
|
143 |
+
|
144 |
+
/* Adjust padding and margins */
|
145 |
+
.gradio-block {
|
146 |
+
padding: 0;
|
147 |
+
}
|
148 |
+
.gradio-row {
|
149 |
+
margin-bottom: 25px;
|
150 |
+
}
|
151 |
+
"""
|
152 |
+
|
153 |
demo.launch()
|
154 |
+
|
155 |
+
|