Ykhl commited on
Commit
dc73d53
·
verified ·
1 Parent(s): 1eae87d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import gradio as gr
4
+
5
+ from groq import Groq
6
+
7
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
8
+
9
+ def summarize_process(text: str):
10
+ """
11
+ summarizes provided description of the proccess in Russian
12
+
13
+ text: provided source
14
+ """
15
+ summarization_prompt = """
16
+ Summarize the provided text in Russian. Use Russian language only.
17
+ Extract the main process and briefly summarize it.
18
+ Include key steps, participants and final result in summary.
19
+ Add those who are responsible for the whole process.
20
+ Return the summarized text in Russian only without any comments and explanations.
21
+
22
+ Return valid JSON with the following schema:
23
+ {
24
+ "summary": "string (generated summary of the provided source)"
25
+ }
26
+
27
+ Text for summarization:\n\n
28
+ """
29
+ summary = client.chat.completions.create(messages=[{"role": "user",
30
+ "content": summarization_prompt + text}],
31
+ model= "deepseek-r1-distill-llama-70b",
32
+ response_format={"type": "json_object"},
33
+ stream=False,
34
+ max_tokens=1024,
35
+ temperature=0.5,
36
+ top_p=0.1
37
+ ).choices[0].message.content
38
+ return json.loads(summary)["summary"]
39
+
40
+ summary_bot = gr.Interface(fn=summarize_process,
41
+ inputs=gr.Textbox(lines=2, placeholder="Ваш текст..."),
42
+ outputs="text",
43
+ title="Summary",
44
+ description="Вставьте сюда описание процесса, и я перескажу его!"
45
+ )
46
+
47
+
48
+ if __name__ == "__main__":
49
+ summary_bot.launch()