FrederickSundeep commited on
Commit
9ce57ba
·
1 Parent(s): 6cb0fca

first commit

Browse files
Files changed (5) hide show
  1. README.md +8 -5
  2. app.py +51 -0
  3. requirements.txt +5 -0
  4. session_log.txt +0 -0
  5. templates/index.html +52 -0
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: AIHRTicketGenerator
3
- emoji: 🌍
4
- colorFrom: red
5
- colorTo: green
6
  sdk: static
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: HR Ticket Generator
3
+ emoji: 📩
4
+ colorFrom: pink
5
+ colorTo: blue
6
  sdk: static
7
+ app_file: app.py
8
  pinned: false
9
  ---
10
 
11
+ # HR Ticket Generator
12
+
13
+ Enter a problem, get a formal HR ticket using AI!
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from transformers import pipeline, set_seed
3
+ from langchain.prompts import PromptTemplate
4
+ from fpdf import FPDF
5
+ import os
6
+ from datetime import datetime
7
+
8
+ app = Flask(__name__)
9
+
10
+ # Load lightweight LLM
11
+ generator = pipeline('text-generation', model='distilgpt2')
12
+ set_seed(42)
13
+
14
+ # Prompt Template using LangChain
15
+ template = PromptTemplate(
16
+ input_variables=["issue"],
17
+ template="Generate a formal HR ticket for the following issue:\n\n{issue}\n\nTicket:"
18
+ )
19
+
20
+ @app.route('/')
21
+ def index():
22
+ return render_template('index.html')
23
+
24
+ @app.route('/generate_ticket', methods=['POST'])
25
+ def generate_ticket():
26
+ user_input = request.form['query']
27
+ prompt = template.format(issue=user_input)
28
+
29
+ result = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
30
+ ticket = result.replace(prompt, '').strip()
31
+
32
+ # Session logging
33
+ with open("session_log.txt", "a") as f:
34
+ f.write(f"\n[{datetime.now()}]\nIssue: {user_input}\nTicket: {ticket}\n")
35
+
36
+ return jsonify({'ticket': ticket})
37
+
38
+ @app.route('/download_pdf', methods=['POST'])
39
+ def download_pdf():
40
+ content = request.form['ticket']
41
+ pdf = FPDF()
42
+ pdf.add_page()
43
+ pdf.set_font("Arial", size=12)
44
+
45
+ for line in content.split('\n'):
46
+ pdf.multi_cell(0, 10, line)
47
+
48
+ filename = "hr_ticket.pdf"
49
+ pdf.output(filename)
50
+
51
+ return jsonify({'success': True, 'file': filename})
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ transformers
3
+ torch
4
+ fpdf
5
+ langchain
session_log.txt ADDED
File without changes
templates/index.html ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HR Ticket Generator</title>
5
+ <style>
6
+ body { font-family: Arial; margin: 40px; }
7
+ input, button { padding: 10px; margin-top: 10px; width: 100%; }
8
+ textarea { width: 100%; height: 150px; margin-top: 20px; }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <h2>HR Ticket Generator</h2>
13
+ <form id="ticketForm">
14
+ <input type="text" name="query" placeholder="Enter your HR issue..." required />
15
+ <button type="submit">Generate Ticket</button>
16
+ </form>
17
+ <textarea id="result" readonly></textarea>
18
+ <button id="downloadBtn" style="display:none;">Download as PDF</button>
19
+
20
+ <script>
21
+ const form = document.getElementById('ticketForm');
22
+ const resultBox = document.getElementById('result');
23
+ const downloadBtn = document.getElementById('downloadBtn');
24
+
25
+ form.onsubmit = async (e) => {
26
+ e.preventDefault();
27
+ const formData = new FormData(form);
28
+ const response = await fetch('/generate_ticket', {
29
+ method: 'POST',
30
+ body: formData
31
+ });
32
+ const data = await response.json();
33
+ resultBox.value = data.ticket;
34
+ downloadBtn.style.display = 'inline-block';
35
+ };
36
+
37
+ downloadBtn.onclick = async () => {
38
+ const ticket = resultBox.value;
39
+ const formData = new FormData();
40
+ formData.append('ticket', ticket);
41
+ const res = await fetch('/download_pdf', {
42
+ method: 'POST',
43
+ body: formData
44
+ });
45
+ const file = await res.json();
46
+ if (file.success) {
47
+ window.location.href = file.file;
48
+ }
49
+ };
50
+ </script>
51
+ </body>
52
+ </html>