File size: 2,004 Bytes
dc73d53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import json
import gradio as gr

from groq import Groq

client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

def summarize_process(text: str):
        """
        summarizes provided description of the proccess in Russian

        text: provided source
        """
        summarization_prompt = """
        Summarize the provided text in Russian. Use Russian language only.
        Extract the main process and briefly summarize it.
        Include key steps, participants and final result in summary.
        Add those who are responsible for the whole process.
        Return the summarized text in Russian only without any comments and explanations.

        Return valid JSON with the following schema:
        {
        "summary": "string (generated summary of the provided source)"
        }

        Text for summarization:\n\n
        """
        summary = client.chat.completions.create(messages=[{"role": "user",
                                                           "content": summarization_prompt + text}],
                                                 model= "deepseek-r1-distill-llama-70b",
                                                 response_format={"type": "json_object"},
                                                 stream=False,
                                                 max_tokens=1024,
                                                 temperature=0.5,
                                                 top_p=0.1
                                                 ).choices[0].message.content
        return json.loads(summary)["summary"]

summary_bot = gr.Interface(fn=summarize_process,
                    inputs=gr.Textbox(lines=2, placeholder="Ваш текст..."),
                    outputs="text",
                    title="Summary",
                    description="Вставьте сюда описание процесса, и я перескажу его!"
                    )


if __name__ == "__main__":
    summary_bot.launch()