Spaces:
Running
Running
File size: 2,002 Bytes
cfd6a01 5e41822 b0129d8 5e41822 f40d377 825da3a 91698af d7e5216 16cf8d1 d7e5216 91698af efdb6c2 ae45b37 efdb6c2 91698af efdb6c2 f40d377 16cf8d1 ce7ed46 f40d377 91eaca5 f40d377 825da3a acab611 5e9b63d c037b23 |
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 48 49 50 51 52 53 54 55 56 57 |
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() |