Spaces:
Sleeping
Sleeping
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() | |