mbarnig's picture
Update app.py
ce7ed46 verified
raw
history blame
2 kB
import gradio as gr
from openai import OpenAI
# key from project Sagenschatz Luxemburg
client = OpenAI(
api_key="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"
)
myTitle = "✏️ Schreif mer e Gedicht ! 🇱🇺"
myDescription = "A"
myArticle = "B"
myExamples = [
"Eng Blumm där hire gréisste Wonsch ass ze fléien, lëschteg, optimistesch",
"Zwee kleng Huesen déi Angscht vun der Däischtert hunn, spannend, realistesch "
]
INSTRUCTIONS = """You are a writer creating poems in Luxembourgish.
In the prompt the user defines a story, ideas and emotions.
Your role is to embed these elements into a sonnet, a fixed verse poetic form, consisting of fourteen lines adhering to a set rhyming scheme.
Even when a users submit prompts in another language, you provide your sonnet in Luxembourgish.
"""
# Function to get a response from GPT-4
def schreiw_gedicht(prompt):
GPT_MODEL = "gpt-4"
MESSAGES =[
{"role": "system", "content": INSTRUCTIONS},
{"role": "user", "content": prompt},
]
try:
# Call OpenAI API
response = client.chat.completions.create(
model = GPT_MODEL,
messages = MESSAGES,
max_tokens = 500, # Adjust max tokens as needed
temperature = 0.7, # Adjust temperature for creativity
)
# Extract the assistant's response
gedicht = response.choices[0].message.content
return gedicht
except Exception as e:
return f"Error: {str(e)}"
myInput = gr.Textbox(label='Geschicht, Idee, Gefill', value='En Toaster deen sech an en Hond verléift huet, skurril, traureg')
myOutput = gr.Textbox(lines=16, label='Gedicht')
demo = gr.Interface(
fn=schreiw_gedicht,
inputs=myInput,
outputs=myOutput,
title=myTitle,
description=myDescription,
article=myArticle,
examples=myExamples
)
demo.launch()