Spaces:
Sleeping
Sleeping
| 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() | |