Unlimitedlevel19 commited on
Commit
4449a29
·
verified ·
1 Parent(s): 9dad436

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datetime import datetime
3
+ from reportlab.lib.pagesizes import A4
4
+ from reportlab.pdfgen import canvas
5
+ from transformers import pipeline
6
+
7
+ # Load AI dari Hugging Face
8
+ ai_assistant = pipeline(
9
+ "text-generation",
10
+ model="mistralai/Mistral-7B-Instruct-v0.2",
11
+ device_map="auto"
12
+ )
13
+
14
+ def qc_ai_recommendation(job_type, notes):
15
+ prompt = f"""
16
+ Saya adalah Quality Control di proyek konstruksi. Jenis pekerjaan: {job_type}.
17
+ Catatan hasil inspeksi: {notes}.
18
+ Berikan saran teknis perbaikan atau tindak lanjut yang jelas.
19
+ """
20
+ result = ai_assistant(prompt, max_length=250, do_sample=True)[0]['generated_text']
21
+ return result
22
+
23
+ def generate_qc_report(project_name, location, job_type, quality_status, notes):
24
+ ai_suggestion = qc_ai_recommendation(job_type, notes)
25
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
26
+
27
+ report_text = f"""
28
+ QC REPORT
29
+ ---------------------------
30
+ Nama Proyek : {project_name}
31
+ Lokasi : {location}
32
+ Jenis Pekerjaan: {job_type}
33
+ Status Mutu : {quality_status}
34
+ Catatan : {notes}
35
+ Rekomendasi AI : {ai_suggestion}
36
+ Waktu Inspeksi : {timestamp}
37
+ """
38
+
39
+ pdf_filename = "/tmp/qc_report.pdf"
40
+ c = canvas.Canvas(pdf_filename, pagesize=A4)
41
+ text = c.beginText(50, 800)
42
+ for line in report_text.strip().split('\n'):
43
+ text.textLine(line)
44
+ c.drawText(text)
45
+ c.save()
46
+
47
+ return ai_suggestion, pdf_filename
48
+
49
+ with gr.Blocks() as app:
50
+ gr.Markdown("# 🏗️ QC Agent — Integrasi AI Rekomendasi Perbaikan")
51
+
52
+ with gr.Row():
53
+ project_name = gr.Textbox(label="Nama Proyek")
54
+ location = gr.Textbox(label="Lokasi Proyek")
55
+
56
+ job_type = gr.Textbox(label="Jenis Pekerjaan")
57
+ quality_status = gr.Radio(["Lulus", "Tidak Lulus"], label="Status Mutu")
58
+ notes = gr.Textbox(label="Catatan Tambahan", lines=3)
59
+
60
+ ai_output = gr.Textbox(label="💡 Rekomendasi AI", lines=5)
61
+ output_pdf = gr.File(label="📥 Download Laporan PDF")
62
+
63
+ submit = gr.Button("🚀 Generate Rekomendasi & PDF")
64
+ submit.click(generate_qc_report,
65
+ inputs=[project_name, location, job_type, quality_status, notes],
66
+ outputs=[ai_output, output_pdf])
67
+
68
+ app.launch()