Spaces:
Sleeping
Sleeping
File size: 2,160 Bytes
22fdbb4 8109087 41eb8f9 00c6a1e 8289444 656a5a1 8289444 f366e70 8289444 f366e70 f0e4975 4bead39 656a5a1 00c6a1e f366e70 22fdbb4 00c6a1e eedb2d2 8109087 7bcd24d 5812f5e f366e70 22fdbb4 04ca4a4 22fdbb4 04ca4a4 22fdbb4 | 1 2 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 65 66 67 68 69 70 |
import gradio as gr
from ctransformers import AutoModelForCausalLM, AutoTokenizer
import time
from datetime import datetime
import shutil
import os
folder_path = "./models" # Change the folder name if needed
if not os.path.exists(folder_path):
os.makedirs(folder_path)
print(f"β
Folder created: {folder_path}")
else:
print(f"π Folder already exists: {folder_path}")
# Define source file and destination folder
source_file1 = "tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf"
source_file2 = "config.json"
# Copy the file
shutil.copy(source_file1, folder_path)
shutil.copy(source_file2, folder_path)
model_path = "./models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf" # Adjust if necessary
if os.path.exists(model_path):
print(f"β
Model found at: {model_path}")
else:
print(f"β Model not found at: {model_path}")
print("π Available files:", os.listdir("./models"))
print("model")
print(datetime.fromtimestamp(time.time()))
model = AutoModelForCausalLM.from_pretrained(folder_path, model_type="llama")
print("done setup")
print(datetime.fromtimestamp(time.time()))
def generate_letter(date, letter_time, purpose, place, sender, receiver):
prompt = (f"Tuliskan surat resmi dengan detail sebagai berikut:\n"
f"Tanggal: {date}\nWaktu: {letter_time}\nTujuan: {purpose}\nTempat: {place}\n"
f"Pengirim: {sender}\nPenerima: {receiver}\n\nSurat:")
response = model(prompt)
return response
# Create the Gradio interface
iface = gr.Interface(
fn=generate_letter,
inputs=[
gr.Textbox(label="Tanggal"),
gr.Textbox(label="Waktu"),
gr.Textbox(label="Tujuan"),
gr.Textbox(label="Tempat"),
gr.Textbox(label="Pengirim"),
gr.Textbox(label="Penerima"),
],
#outputs=gr.Textbox(label="Generated Letter"),
outputs=gr.Textbox(label="Surat yang dibuat secara otomatis"),
#title="Letter Generator",
title="Generator Surat",
#description="Enter the details and generate a formal letter automatically."
description="Tuliskan detail informasi surat yang ingin dibuat."
)
# Launch the app
if __name__ == "__main__":
iface.launch()
|