baptistejamin commited on
Commit
67df4ab
1 Parent(s): f50ea06
Files changed (1) hide show
  1. app.py +32 -25
app.py CHANGED
@@ -4,33 +4,40 @@ import os
4
 
5
  client = OpenAI(api_key=os.getenv("OPENAI_KEY"))
6
 
7
- def generate_response(prompt):
8
- response = client.chat.completions.create(
9
- model="ft:gpt-3.5-turbo-0613:personal::8C0XIiJC",
10
- messages=[
11
- {
12
- "role": "user",
13
- "content": "Trouve un titre pour cet article:\n\n" + prompt
14
- }
15
- ],
16
- temperature=0.5,
17
- max_tokens=256,
18
- top_p=1,
19
- frequency_penalty=0,
20
- presence_penalty=0
21
- )
 
 
 
 
 
 
 
22
 
23
- return response.choices[0].message.content
24
 
25
  def main():
26
- interface = gr.Interface(
27
- fn=generate_response,
28
- inputs=gr.Textbox(lines=50, placeholder="Entrez votre article ici..."),
29
- outputs="text",
30
- title="Générateur de titre",
31
- description="Entrez un article"
32
- )
33
- interface.launch(auth=("admin", os.getenv("PASSWORD")))
34
 
35
  if __name__ == "__main__":
36
- main()
 
4
 
5
  client = OpenAI(api_key=os.getenv("OPENAI_KEY"))
6
 
7
+ def generate_response(tache, article):
8
+ model = "ft:gpt-3.5-turbo-0613:personal::8C0XIiJC"
9
+ prefix = "Trouve un titre pour cet article:\n\n"
10
+
11
+ if tache == "chapeau":
12
+ model = "gpt-3.5-turbo"
13
+ prefix = "Trouve un premier paragraphe introductif de 200 signes pour cet article:\n\n"
14
+
15
+ response = client.chat.completions.create(
16
+ model=model,
17
+ messages=[
18
+ {
19
+ "role": "user",
20
+ "content": prefix + article
21
+ }
22
+ ],
23
+ temperature=0.5,
24
+ max_tokens=256,
25
+ top_p=1,
26
+ frequency_penalty=0,
27
+ presence_penalty=0
28
+ )
29
 
30
+ return response.choices[0].message.content
31
 
32
  def main():
33
+ interface = gr.Interface(
34
+ fn=generate_response,
35
+ inputs=[gr.Dropdown(choices=["titre", "chapeau"], value="titre"), gr.Textbox(lines=50, placeholder="Entrez votre article ici...")],
36
+ outputs="text",
37
+ title="Générateur de titre",
38
+ description="Entrez un article"
39
+ )
40
+ interface.launch(auth=("admin", os.getenv("PASSWORD")))
41
 
42
  if __name__ == "__main__":
43
+ main()