File size: 1,420 Bytes
07471eb
0295484
07471eb
 
 
d0ac486
07471eb
5f7ee7d
07471eb
7e55e8b
 
 
 
 
 
07471eb
 
5f7ee7d
07471eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6254bf5
07471eb
5f7ee7d
07471eb
 
 
6254bf5
07471eb
 
 
 
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
import openai
import os 
import gradio as gr

# Configure votre clé API
openai.api_key = os.environ['OpenaiKey']

def writing_assistant(debut, suite, instructions):
    # Construction de la requête

    with open('instructions.txt', 'r') as fichier:
    # Lecture du contenu du fichier
    instructions = fichier.read() + "\n" + instructions
    
    prompt = f"DEBUT = '{debut}'\n SUITE = '{suite}' \n INSTRUCTIONS = {instructions}"

    messages = [
        {"role": "system", "content": f"Tu es un assistant d'écriture. Tu aides un auteur contemporain à écrire, en t'inspirant de son style littéraire."},
        {"role": "user", "content": prompt}
    ]

    # Call GPT-3.5-turbo API
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages,
    )

    # Get generated text
    texte_reecrit = response.choices[0].message['content'].strip()

    return texte_reecrit    

# Création de l'interface Gradio
iface = gr.Interface(
    fn=writing_assistant,
    inputs=[
        gr.inputs.Textbox(lines=5, label="Début"),
        gr.inputs.Textbox(lines=5, label="Suite")
        gr.inputs.Textbox(lines=2, label="Instructions additionnelles")
    ],
    outputs=gr.outputs.Textbox(label="Texte réécrit"),
    title="Assistant d'écriture",
    description="Réécrit un brouillon en respectant un début avec un style donné."
)

# Lancer l'interface
iface.launch()