Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,32 @@
|
|
1 |
-
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
client = InferenceClient("HooshvareLab/gpt2-fa")
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
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 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
demo = gr.Interface(
|
28 |
-
fn=
|
29 |
inputs=[
|
30 |
gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."),
|
31 |
-
gr.Slider(1,
|
32 |
-
gr.Slider(0.1,
|
33 |
-
gr.Slider(0.1, 1.0, value=0.
|
34 |
],
|
35 |
outputs=gr.Textbox(label="گزارش رسمی تولید شده"),
|
36 |
-
title="گزارشنویس
|
37 |
-
description="اطلاعات
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
-
demo.launch()
|
|
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
|
4 |
client = InferenceClient("HooshvareLab/gpt2-fa")
|
5 |
|
6 |
+
def generate_report_farsi(prompt, max_tokens, temperature, top_p):
|
7 |
+
full_prompt = f"گزارش رسمی عملیات نظامی بر اساس اطلاعات زیر تهیه کن:\n{prompt}\nگزارش:"
|
8 |
+
output = client.text_generation(
|
9 |
+
prompt=full_prompt,
|
10 |
+
max_new_tokens=max_tokens,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
temperature=temperature,
|
12 |
top_p=top_p,
|
13 |
+
do_sample=True,
|
14 |
+
repetition_penalty=1.1
|
15 |
+
)
|
16 |
+
return output
|
17 |
|
18 |
demo = gr.Interface(
|
19 |
+
fn=generate_report_farsi,
|
20 |
inputs=[
|
21 |
gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."),
|
22 |
+
gr.Slider(1, 512, value=200, label="حداکثر توکن خروجی"),
|
23 |
+
gr.Slider(0.1, 2.0, value=0.9, step=0.1, label="دمای خلاقیت (temperature)"),
|
24 |
+
gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p"),
|
25 |
],
|
26 |
outputs=gr.Textbox(label="گزارش رسمی تولید شده"),
|
27 |
+
title="گزارشنویس فارسی عملیات نظامی",
|
28 |
+
description="اطلاعات عملیات را وارد کن تا گزارش فارسی تولید شود."
|
29 |
)
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
+
demo.launch()
|