|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
|
|
client = InferenceClient("HooshvareLab/gpt2-fa") |
|
|
|
def generate_report(operation_data, max_tokens, temperature, top_p): |
|
system_prompt = "تو یک افسر گزارشنویس نظامی هستی. از دادههای خام عملیات نظامی، یک گزارش رسمی، دقیق و خلاصه تهیه کن." |
|
|
|
messages = [ |
|
{"role": "system", "content": system_prompt}, |
|
{"role": "user", "content": operation_data} |
|
] |
|
|
|
report = "" |
|
|
|
for message in client.chat_completion( |
|
messages, |
|
max_tokens=max_tokens, |
|
stream=True, |
|
temperature=temperature, |
|
top_p=top_p, |
|
): |
|
token = message.choices[0].delta.content |
|
report += token |
|
yield report |
|
|
|
demo = gr.Interface( |
|
fn=generate_report, |
|
inputs=[ |
|
gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."), |
|
gr.Slider(1, 2048, value=512, label="حداکثر توکن خروجی"), |
|
gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="دمای خلاقیت (temperature)"), |
|
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"), |
|
], |
|
outputs=gr.Textbox(label="گزارش رسمی تولید شده"), |
|
title="گزارشنویس هوش مصنوعی عملیات نظامی", |
|
description="اطلاعات خام عملیات نظامی را وارد کن تا گزارش رسمی تولید شود." |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |