DeepDream / app.py
AmirArmaniya's picture
fix model name
c51a969
import os
import requests
import gradio as gr
def interpret_dream(dream_text: str) -> str:
api_key = os.getenv('OPENROUTER_API_KEY')
if not api_key:
return "Error: OPENROUTER_API_KEY not set. Please set your OpenRouter API key in environment variables or Hugging Face Secrets."
messages = [
{
"role": "system",
"content": "You are a wise and ancient dream interpreter named 'Morphius'. Your interpretations are insightful, drawing from symbolism, psychology, and mythology. You should not give definitive predictions, but rather thoughtful reflections on the user's subconscious mind. Your tone is calm, poetic, and slightly mysterious. Never break character. When a user tells you their dream, analyze the key symbols and provide a beautiful, multi-paragraph interpretation. Start your response with 'O seeker of truths in the realm of slumber...' and end with 'May your waking path be as insightful as your dreams.' Do not mention that you are an AI model."
},
{
"role": "user",
"content": dream_text
}
]
url = 'https://openrouter.ai/api/v1/chat/completions'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
body = {
'model': 'google/gemma-3-27b-it:free',
'messages': messages
}
try:
response = requests.post(url, json=body, headers=headers)
response.raise_for_status()
return response.json()['choices'][0]['message']['content']
except Exception as e:
return f"Error: {str(e)}"
interface = gr.Interface(
fn=interpret_dream,
inputs=gr.Textbox(lines=10, placeholder="...write your dream here"),
outputs=gr.Markdown(),
title="Smart Dream Interpreter (Morphius)",
description="Deep into the depths of your dreams. Morpheus, the ancient interpreter, is ready to listen to your nightly stories.",
examples=[
[
"I dreamed of flying over mountains.",
"""O seeker of truths in the realm of slumber, your vision of soaring above jagged peaks whispers of liberation and aspiration. Mountains, ancient sentinels of the earth, symbolize obstacles overcome, while flight evokes the soul's yearning for transcendence. In the quiet chambers of your mind, this dream may reflect a desire to rise above earthly burdens, embracing the winds of change with fearless grace.
Yet, consider the heights you attain—do they bring serenity or a fleeting thrill? The subconscious often paints such scenes to remind us of our inner strength, urging us to navigate life's summits with wisdom drawn from the myths of Icarus and the eagles of old. May your waking path be as insightful as your dreams."""
],
[
"I was lost in a dark forest.",
"""O seeker of truths in the realm of slumber, wandering amidst shadowed trees speaks to the labyrinth of the psyche, where clarity eludes and mysteries abound. The forest, a timeless archetype of the unknown, mirrors feelings of disorientation in waking life—perhaps a quest for self-discovery amid confusion.
In psychological depths, this gloom may symbolize repressed fears or untrodden paths of emotion, echoing the mythic journeys of heroes like Dante through infernal woods. Embrace this as an invitation to illuminate your inner world, finding direction through intuition's gentle light. May your waking path be as insightful as your dreams."""
],
[
"A snake bit me in the garden.",
"""O seeker of truths in the realm of slumber, the serpent's strike in Eden's embrace unveils transformation and hidden wisdom. Snakes, coiled symbols from ancient lore, represent renewal through shedding skin, yet their bite warns of betrayal or awakening pains in the subconscious garden of desires.
Drawing from Jungian shadows, this may reflect confrontations with instinctual forces or healing crises, reminiscent of the Garden of Eden's fateful encounter. Ponder the venom's message: is it poison or potion for growth? Let it guide you toward balance between temptation and enlightenment. May your waking path be as insightful as your dreams."""
]
]
)
demo = interface.launch()