AmirArmaniya commited on
Commit
ed93164
·
1 Parent(s): cbc3f78

Add project files

Browse files
Files changed (4) hide show
  1. README.md +142 -0
  2. README.mdZone.Identifier +2 -0
  3. app.py +66 -0
  4. app.pyZone.Identifier +2 -0
README.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # English:
2
+
3
+ # Smart Dream Interpreter (Morphius) 🔮
4
+
5
+ [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME)
6
+
7
+ A simple and creative web application for dream interpretation and analysis using the power of artificial intelligence. The project allows users to enter their dream text and receive a poetic and psychological interpretation based on symbols.
8
+
9
+ ![Screenshot of the application interface](https://example.com/screenshot.png) ## ✨ Features
10
+
11
+ * **Simple and beautiful user interface:** Built with `Gradio` for a smooth user experience.
12
+ * **Powerful AI engine:** Using the advanced `google/gemma-2-27b-it` model via the free OpenRouter API.
13
+ * **Personalized:** The AI ​​model appears as an ancient and wise dream interpreter named "Morpheus".
14
+ * **Ready to deploy:** Easily and for free to deploy in Hugging Face Spaces.
15
+
16
+ ## 🛠️ Technologies Used
17
+
18
+ * **User Interface:** [Gradio](https://www.gradio.app/)
19
+ * **AI Model:** [Google Gemma 2 27B IT](https://openrouter.ai/models/google/gemma-2-27b-it)
20
+ * **API Provider:** [OpenRouter](https://openrouter.ai/)
21
+ * **Deployment Platform:** [Hugging Face Spaces](https://huggingface.co/spaces)
22
+
23
+ ## 🚀 Setup and Run Locally
24
+
25
+ To run this project on your personal system, follow these steps:
26
+
27
+ 1. **Clone the repository:**
28
+ ```bash
29
+ git clone [https://github.com/YOUR_USERNAME/dream-interpreter.git](https://github.com/YOUR_USERNAME/dream-interpreter.git)
30
+ cd dream-interpreter
31
+ ```
32
+
33
+ 2. **Install Prerequisites:**
34
+ It is recommended to use a virtual environment.
35
+ ```bash
36
+ python -m venv venv
37
+ source venv/bin/activate # On Windows use `venv\Scripts\activate`
38
+ pip install -r requirements.txt
39
+ ```
40
+
41
+ 3. **Set up your API key:**
42
+ * Create an account on [OpenRouter.ai](https://openrouter.ai/) and get an API key.
43
+ * Create a file called `.env` in the root of your project and put your key in it:
44
+ ```
45
+ OPENROUTER_API_KEY="sk-or-..."
46
+ ```
47
+ * The `app.py` file is written to read this variable automatically.
48
+
49
+ 4. **Run the program:**
50
+ ```bash
51
+ gradio app.py
52
+ ```
53
+ Now you can view the application in your browser at `http://127.0.0.1:7860`.
54
+
55
+ ## ☁️ Deploying to Hugging Face Spaces
56
+
57
+ This project is optimized for deployment to Spaces:
58
+
59
+ 1. Create a new Space of type **Gradio SDK** in Hugging Face.
60
+ 2. Upload the `app.py` and `requirements.txt` files to it.
61
+ 3. Go to **Settings > Secrets** and create a new Secret named `OPENROUTER_API_KEY` and the value of your API key.
62
+ 4. Space will automatically build and run the application.
63
+
64
+ ## 🤝 Contributions
65
+
66
+ Any contributions, bug reports, or suggestions for improving the project are welcome. Please open an Issue or submit a Pull Request.
67
+
68
+ ## 📄 License
69
+
70
+ This project is released under the MIT License.
71
+
72
+ -------------------------------------------------------------------------
73
+
74
+ # persian
75
+ # مفسر خواب هوشمند (Morphius) 🔮
76
+
77
+ [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME)
78
+
79
+ یک وب اپلیکیشن ساده و خلاقانه برای تعبیر و تحلیل خواب با استفاده از قدرت هوش مصنوعی. این پروژه به کاربران اجازه می‌دهد تا متن خواب خود را وارد کرده و تفسیری شاعرانه و روانشناسانه بر اساس نمادها دریافت کنند.
80
+
81
+ ![تصویری از رابط کاربری برنامه](https://example.com/screenshot.png) ## ✨ ویژگی‌ها
82
+
83
+ * **رابط کاربری ساده و زیبا:** ساخته شده با `Gradio` برای تجربه کاربری روان.
84
+ * **موتور هوش مصنوعی قدرتمند:** استفاده از مدل پیشرفته `google/gemma-2-27b-it` از طریق API رایگان OpenRouter.
85
+ * **شخصیت‌پردازی شده:** مدل هوش مصنوعی در نقش یک مفسر خواب باستانی و خردمند به نام "مورفیوس" ظاهر می‌شود.
86
+ * **آماده استقرار:** به راحتی و به صورت رایگان در Hugging Face Spaces قابل استقرار است.
87
+
88
+ ## 🛠️ تکنولوژی‌های استفاده شده
89
+
90
+ * **رابط کاربری:** [Gradio](https://www.gradio.app/)
91
+ * **مدل هوش مصنوعی:** [Google Gemma 2 27B IT](https://openrouter.ai/models/google/gemma-2-27b-it)
92
+ * **ارائه دهنده API:** [OpenRouter](https://openrouter.ai/)
93
+ * **پلتفرم استقرار:** [Hugging Face Spaces](https://huggingface.co/spaces)
94
+
95
+ ## 🚀 راه‌اندازی و اجرا به صورت محلی (Local)
96
+
97
+ برای اجرای این پروژه روی سیستم شخصی خود، مراحل زیر را دنبال کنید:
98
+
99
+ 1. **کلون کردن ریپازیتوری:**
100
+ ```bash
101
+ git clone [https://github.com/YOUR_USERNAME/dream-interpreter.git](https://github.com/YOUR_USERNAME/dream-interpreter.git)
102
+ cd dream-interpreter
103
+ ```
104
+
105
+ 2. **نصب پیش‌نیازها:**
106
+ توصیه می‌شود از یک محیط مجازی (virtual environment) استفاده کنید.
107
+ ```bash
108
+ python -m venv venv
109
+ source venv/bin/activate # On Windows use `venv\Scripts\activate`
110
+ pip install -r requirements.txt
111
+ ```
112
+
113
+ 3. **تنظیم کلید API:**
114
+ * یک حساب کاربری در [OpenRouter.ai](https://openrouter.ai/) بسازید و یک کلید API دریافت کنید.
115
+ * یک فایل به نام `.env` در ریشه پروژه بسازید و کلید خود را در آن قرار دهید:
116
+ ```
117
+ OPENROUTER_API_KEY="sk-or-..."
118
+ ```
119
+ * فایل `app.py` طوری نوشته شده که این متغیر را به صورت خودکار بخواند.
120
+
121
+ 4. **اجرای برنامه:**
122
+ ```bash
123
+ gradio app.py
124
+ ```
125
+ حالا می‌توانید برنامه را در مرورگر خود از طریق آدرس `http://127.0.0.1:7860` مشاهده کنید.
126
+
127
+ ## ☁️ استقرار در Hugging Face Spaces
128
+
129
+ این پروژه برای استقرار در Spaces بهینه شده است:
130
+
131
+ 1. یک Space جدید از نوع **Gradio SDK** در Hugging Face بسازید.
132
+ 2. فایل‌های `app.py` و `requirements.txt` را در آن آپلود کنید.
133
+ 3. به بخش **Settings > Secrets** بروید و یک Secret جدید با نام `OPENROUTER_API_KEY` و مقدار کلید API خود بسازید.
134
+ 4. Space به طور خودکار برنامه را ساخته و اجرا خواهد کرد.
135
+
136
+ ## 🤝 مشارکت
137
+
138
+ از هرگونه مشارکت، گزارش باگ یا پیشنهاد برای بهبود پروژه استقبال می‌شود. لطفاً یک Issue باز کنید یا یک Pull Request ارسال نمایید.
139
+
140
+ ## 📄 مجوز
141
+
142
+ این پروژه تحت مجوز MIT منتشر شده است.
README.mdZone.Identifier ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+
5
+ def interpret_dream(dream_text: str) -> str:
6
+ api_key = os.getenv('OPENROUTER_API_KEY')
7
+ if not api_key:
8
+ return "Error: OPENROUTER_API_KEY not set. Please set your OpenRouter API key in environment variables or Hugging Face Secrets."
9
+
10
+ messages = [
11
+ {
12
+ "role": "system",
13
+ "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."
14
+ },
15
+ {
16
+ "role": "user",
17
+ "content": dream_text
18
+ }
19
+ ]
20
+
21
+ url = 'https://openrouter.ai/api/v1/chat/completions'
22
+ headers = {
23
+ 'Authorization': f'Bearer {api_key}',
24
+ 'Content-Type': 'application/json'
25
+ }
26
+ body = {
27
+ 'model': 'google/gemma-2-27b-it',
28
+ 'messages': messages
29
+ }
30
+
31
+ try:
32
+ response = requests.post(url, json=body, headers=headers)
33
+ response.raise_for_status()
34
+ return response.json()['choices'][0]['message']['content']
35
+ except Exception as e:
36
+ return f"Error: {str(e)}"
37
+
38
+ interface = gr.Interface(
39
+ fn=interpret_dream,
40
+ inputs=gr.Textbox(lines=10, placeholder="...write your dream here"),
41
+ outputs=gr.Markdown(),
42
+ title="Smart Dream Interpreter (Morphius)",
43
+ description="Deep into the depths of your dreams. Morpheus, the ancient interpreter, is ready to listen to your nightly stories.",
44
+ examples=[
45
+ [
46
+ "I dreamed of flying over mountains.",
47
+ """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.
48
+
49
+ 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."""
50
+ ],
51
+ [
52
+ "I was lost in a dark forest.",
53
+ """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.
54
+
55
+ 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."""
56
+ ],
57
+ [
58
+ "A snake bit me in the garden.",
59
+ """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.
60
+
61
+ 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."""
62
+ ]
63
+ ]
64
+ )
65
+
66
+ demo = interface.launch()
app.pyZone.Identifier ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [ZoneTransfer]
2
+ ZoneId=3