Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,41 @@
|
|
1 |
-
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
{prompt}
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
🎯 هدف عملیات:
|
17 |
-
📋 شرح اقدامات:
|
18 |
-
🎖️ نتایج و دستاوردها:
|
19 |
-
⚠️ تلفات و خسارات:
|
20 |
-
🔚 نتیجهگیری:
|
21 |
-
"""
|
22 |
-
output = client.text_generation(
|
23 |
-
prompt=formatted_prompt,
|
24 |
-
max_new_tokens=max_tokens,
|
25 |
temperature=temperature,
|
26 |
top_p=top_p,
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
demo = gr.Interface(
|
33 |
-
fn=
|
34 |
inputs=[
|
35 |
gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."),
|
36 |
-
gr.Slider(1,
|
37 |
-
gr.Slider(0.1,
|
38 |
-
gr.Slider(0.1, 1.0, value=0.
|
39 |
],
|
40 |
-
outputs=gr.Textbox(label="
|
41 |
-
title="
|
42 |
-
description="اطلاعات عملیات را وارد کن تا گزارش
|
43 |
)
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
-
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
client = InferenceClient("openai/whisper-small")
|
5 |
|
6 |
+
def generate_report(operation_data, max_tokens, temperature, top_p):
|
7 |
+
system_prompt = "تو یک افسر گزارشنویس نظامی هستی. از دادههای خام عملیات نظامی، یک گزارش رسمی، دقیق و خلاصه تهیه کن."
|
8 |
|
9 |
+
messages = [
|
10 |
+
{"role": "system", "content": system_prompt},
|
11 |
+
{"role": "user", "content": operation_data}
|
12 |
+
]
|
13 |
|
14 |
+
report = ""
|
|
|
15 |
|
16 |
+
for message in client.chat_completion(
|
17 |
+
messages,
|
18 |
+
max_tokens=max_tokens,
|
19 |
+
stream=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
temperature=temperature,
|
21 |
top_p=top_p,
|
22 |
+
):
|
23 |
+
token = message.choices[0].delta.content
|
24 |
+
report += token
|
25 |
+
yield report
|
26 |
|
27 |
demo = gr.Interface(
|
28 |
+
fn=generate_report,
|
29 |
inputs=[
|
30 |
gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."),
|
31 |
+
gr.Slider(1, 2048, value=512, label="حداکثر توکن خروجی"),
|
32 |
+
gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="دمای خلاقیت (temperature)"),
|
33 |
+
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
|
34 |
],
|
35 |
+
outputs=gr.Textbox(label="گزارش رسمی تولید شده"),
|
36 |
+
title="گزارشنویس هوش مصنوعی عملیات نظامی",
|
37 |
+
description="اطلاعات خام عملیات نظامی را وارد کن تا گزارش رسمی تولید شود."
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
+
demo.launch()
|