File size: 1,416 Bytes
87bee29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pyperclip
import pickle
import random

# Open the pickle file in read mode
with open("data.pickle", "rb") as file:
  # Load the pickled dictionary from the file
  data = pickle.load(file)

# Print the dictionary

def classify_text(num, word):
    list_inputs = data[num][word] 
    random.shuffle(list_inputs)
    prompt = '\n\n'.join(list_inputs)
    return prompt + f'\n\nstreść powyższe teksty i scal je w jeden rozdział zatytuowany "{word}"'

def copy_to_clipboard(text, button):
    pyperclip.copy(text)
    button = 'Copied'

with gr.Blocks() as interface:
    gr.Markdown(
    """
    # <center>AA report generator hepler</center>
    Wybierz numer ćwiczenia, sekcję i przeklej tekst do ChatGPT.
    """)
    with gr.Row():
        with gr.Column():
            inputs = gr.Dropdown(choices=list(range(10)), label="Numer ćwiczenia", value=0)
            inputs2 = gr.Radio(choices=["wstęp", "opis stanowiska", "realizacja ćwiczenia", "wnioski"], label="Sekcja", value='wstęp')
            button = gr.Button(value="Copy to clipboard")
        with gr.Column():
            output = gr.Textbox(label="Tekst do przeklejenia", value=classify_text(0, 'wstęp'))

    inputs.change(classify_text, [inputs, inputs2], output)
    inputs2.change(classify_text, [inputs, inputs2], output)
    button.click(copy_to_clipboard, [output, button], None)

interface.launch(inline=False)