File size: 1,091 Bytes
f50ea06
 
 
 
 
 
67df4ab
 
 
 
5f11692
b86961e
 
67df4ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f50ea06
67df4ab
f50ea06
 
67df4ab
 
5f11692
67df4ab
 
 
 
 
f50ea06
 
67df4ab
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
import gradio as gr
from openai import OpenAI
import os

client = OpenAI(api_key=os.getenv("OPENAI_KEY"))

def generate_response(tache, article):
  model = "ft:gpt-3.5-turbo-0613:personal::8C0XIiJC"
  prefix = "Trouve un titre pour cet article:\n\n"
  
  if tache == "chapo":
    model = "ft:gpt-3.5-turbo-1106:personal::8lcbldD1"
    prefix = "Trouve un chapo pour cet article:\n\n"
  
  response = client.chat.completions.create(
    model=model,
    messages=[
      {
        "role": "user",
        "content": prefix +  article
      }
    ],
    temperature=0.5,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
  )

  return response.choices[0].message.content

def main():
  interface = gr.Interface(
    fn=generate_response,
    inputs=[gr.Dropdown(choices=["titre", "chapo"], value="titre"), gr.Textbox(lines=50, placeholder="Entrez votre article ici...")],
    outputs="text",
    title="Générateur de titre",
    description="Entrez un article"
  )
  interface.launch(auth=("admin", os.getenv("PASSWORD")))

if __name__ == "__main__":
  main()