Update app.py
Browse files
app.py
CHANGED
@@ -3,42 +3,29 @@ import os
|
|
3 |
from datetime import datetime
|
4 |
from reportlab.lib.pagesizes import A4
|
5 |
from reportlab.pdfgen import canvas
|
6 |
-
from transformers import
|
7 |
|
8 |
-
#
|
9 |
-
hf_token = os.getenv("HF_TOKEN")
|
10 |
-
|
11 |
-
# Load tokenizer dan model
|
12 |
-
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2", token=hf_token)
|
13 |
-
|
14 |
-
# Gunakan pipeline untuk kemudahan
|
15 |
ai_assistant = pipeline(
|
16 |
"text-generation",
|
17 |
-
model="
|
18 |
-
|
19 |
-
device_map="auto",
|
20 |
-
token=hf_token
|
21 |
)
|
22 |
|
23 |
def qc_ai_recommendation(job_type, notes):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
prompt = tokenizer.apply_chat_template(messages, return_tensors=None)
|
31 |
|
32 |
-
|
33 |
-
result = ai_assistant(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)[0]['generated_text']
|
34 |
|
35 |
-
# Ekstrak respons (
|
36 |
-
|
|
|
37 |
|
38 |
-
# Hapus token akhir jika ada
|
39 |
-
if response.endswith("</s>"):
|
40 |
-
response = response[:-4].strip()
|
41 |
-
|
42 |
return response
|
43 |
|
44 |
def generate_qc_report(project_name, location, job_type, quality_status, notes):
|
@@ -86,9 +73,4 @@ with gr.Blocks() as app:
|
|
86 |
inputs=[project_name, location, job_type, quality_status, notes],
|
87 |
outputs=[ai_output, output_pdf])
|
88 |
|
89 |
-
# Periksa jika token tersedia
|
90 |
-
if not hf_token:
|
91 |
-
print("⚠️ Perhatian: Token Hugging Face tidak ditemukan. Aplikasi mungkin tidak bisa mengakses model Mistral-7B-Instruct-v0.2.")
|
92 |
-
print("Silakan tambahkan token di Settings Space Anda dengan nama 'HF_TOKEN'")
|
93 |
-
|
94 |
app.launch()
|
|
|
3 |
from datetime import datetime
|
4 |
from reportlab.lib.pagesizes import A4
|
5 |
from reportlab.pdfgen import canvas
|
6 |
+
from transformers import pipeline
|
7 |
|
8 |
+
# Load AI dari Hugging Face menggunakan model yang terbukti bekerja tanpa autentikasi
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
ai_assistant = pipeline(
|
10 |
"text-generation",
|
11 |
+
model="facebook/opt-350m", # Model kecil yang tidak memerlukan autentikasi
|
12 |
+
device_map="auto"
|
|
|
|
|
13 |
)
|
14 |
|
15 |
def qc_ai_recommendation(job_type, notes):
|
16 |
+
prompt = f"""
|
17 |
+
Saya adalah Quality Control di proyek konstruksi. Jenis pekerjaan: {job_type}.
|
18 |
+
Catatan hasil inspeksi: {notes}.
|
19 |
+
Berikan saran teknis perbaikan atau tindak lanjut yang jelas.
|
20 |
+
Jawab:
|
21 |
+
"""
|
|
|
22 |
|
23 |
+
result = ai_assistant(prompt, max_length=250, do_sample=True, temperature=0.7)[0]['generated_text']
|
|
|
24 |
|
25 |
+
# Ekstrak respons (setelah "Jawab:")
|
26 |
+
response_start = result.find("Jawab:") + len("Jawab:")
|
27 |
+
response = result[response_start:].strip()
|
28 |
|
|
|
|
|
|
|
|
|
29 |
return response
|
30 |
|
31 |
def generate_qc_report(project_name, location, job_type, quality_status, notes):
|
|
|
73 |
inputs=[project_name, location, job_type, quality_status, notes],
|
74 |
outputs=[ai_output, output_pdf])
|
75 |
|
|
|
|
|
|
|
|
|
|
|
76 |
app.launch()
|