| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| |
| model_id = "gpt2" |
|
|
| try: |
| |
| pipe = pipeline("text-generation", model=model_id) |
| except Exception as e: |
| print(f"Error loading model: {e}") |
|
|
| def zew_chat(message, history): |
| |
| |
| training_pattern = ( |
| "Question: Who are you?\n" |
| "Assistant: I am ZewAI, the official assistant for Zako Technology Labs.\n\n" |
| "Question: What is ZTL?\n" |
| "Assistant: ZTL stands for Zako Technology Labs, a software and hardware innovation group.\n\n" |
| "Question: Tell me about ZewpolOS.\n" |
| "Assistant: ZewpolOS is an advanced web-based operating system project from ZTL.\n\n" |
| ) |
| |
| |
| full_prompt = f"{training_pattern}Question: {message}\nAssistant:" |
| |
| output = pipe( |
| full_prompt, |
| max_new_tokens=40, |
| do_sample=True, |
| temperature=0.3, |
| top_k=50, |
| repetition_penalty=1.5, |
| pad_token_id=50256 |
| ) |
| |
| raw_text = output[0]['generated_text'] |
| |
| |
| if "Assistant:" in raw_text: |
| |
| return raw_text.split("Assistant:")[-1].strip().split("\n")[0] |
| |
| return "I am ZewAI. How can I help with ZTL?" |
|
|
| |
| full_prompt = f"{system_instruction}\nUser: {message}\nAssistant:" |
| |
| |
| output = pipe( |
| full_prompt, |
| max_new_tokens=60, |
| do_sample=True, |
| temperature=0.4, |
| top_k=40, |
| top_p=0.9, |
| repetition_penalty=1.3, |
| pad_token_id=50256 |
| ) |
| |
| |
| |
| raw_text = output[0]['generated_text'] |
| if "Assistant:" in raw_text: |
| return raw_text.split("Assistant:")[-1].strip() |
| |
| return raw_text |
|
|
| |
| |
| demo = gr.ChatInterface( |
| fn=zew_chat, |
| title="ZewAI Official (ZTL)", |
| description="Developed by Zako Technology Labs for ZewpolOS 4 pine trunk." |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|
|
|