Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- .github/workflows/update_space.yml +28 -0
- .gitignore +2 -0
- .gradio/certificate.pem +31 -0
- AirlineAssisntantAI.png +0 -0
- Notebooks/Initial_notebook.ipynb +225 -0
- README.md +4 -8
- appV01.py +85 -0
- appV01_gradio.py +340 -0
- out.wav +3 -0
- requirements.txt +8 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
out.wav filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/update_space.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Run Python script
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
build:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout
|
| 14 |
+
uses: actions/checkout@v2
|
| 15 |
+
|
| 16 |
+
- name: Set up Python
|
| 17 |
+
uses: actions/setup-python@v2
|
| 18 |
+
with:
|
| 19 |
+
python-version: '3.9'
|
| 20 |
+
|
| 21 |
+
- name: Install Gradio
|
| 22 |
+
run: python -m pip install gradio
|
| 23 |
+
|
| 24 |
+
- name: Log in to Hugging Face
|
| 25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
| 26 |
+
|
| 27 |
+
- name: Deploy to Spaces
|
| 28 |
+
run: gradio deploy
|
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
.env
|
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+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[
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "2b1ea573",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# Working the Simple ChatBot using Mem0"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "code",
|
| 13 |
+
"execution_count": 12,
|
| 14 |
+
"id": "3c17c4cc",
|
| 15 |
+
"metadata": {},
|
| 16 |
+
"outputs": [],
|
| 17 |
+
"source": [
|
| 18 |
+
"# imports\n",
|
| 19 |
+
"import os\n",
|
| 20 |
+
"import json\n",
|
| 21 |
+
"from dotenv import load_dotenv\n",
|
| 22 |
+
"from mem0 import MemoryClient\n",
|
| 23 |
+
"from google import genai\n",
|
| 24 |
+
"from IPython.display import Markdown"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": 3,
|
| 30 |
+
"id": "c0a6c4d8",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [
|
| 33 |
+
{
|
| 34 |
+
"name": "stdout",
|
| 35 |
+
"output_type": "stream",
|
| 36 |
+
"text": [
|
| 37 |
+
"AIzaSyCOvxW9ffBqFVOAhmoEVcupUzwjOqLbs2c m0-Qtvimm8HzvFp0pR2hJAdenPrxgsQM2udF5cfDlO4\n"
|
| 38 |
+
]
|
| 39 |
+
}
|
| 40 |
+
],
|
| 41 |
+
"source": [
|
| 42 |
+
"# getting api keys\n",
|
| 43 |
+
"load_dotenv()\n",
|
| 44 |
+
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
|
| 45 |
+
"memo_api_key = os.getenv('MEM_API_KEY')\n",
|
| 46 |
+
"print(google_api_key, memo_api_key)"
|
| 47 |
+
]
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"cell_type": "code",
|
| 51 |
+
"execution_count": 6,
|
| 52 |
+
"id": "f4bde7b8",
|
| 53 |
+
"metadata": {},
|
| 54 |
+
"outputs": [
|
| 55 |
+
{
|
| 56 |
+
"name": "stdout",
|
| 57 |
+
"output_type": "stream",
|
| 58 |
+
"text": [
|
| 59 |
+
"The IPL 2025 hasn't happened yet! It's still in the future.\n",
|
| 60 |
+
"\n",
|
| 61 |
+
"The Indian Premier League typically takes place around March-May each year.\n",
|
| 62 |
+
"\n",
|
| 63 |
+
"The most recent IPL season was in 2024, and the **Kolkata Knight Riders (KKR)** won the IPL 2024 trophy.\n",
|
| 64 |
+
"\n",
|
| 65 |
+
"You'll have to wait until the tournament concludes in May 2025 to find out who wins that edition!\n"
|
| 66 |
+
]
|
| 67 |
+
}
|
| 68 |
+
],
|
| 69 |
+
"source": [
|
| 70 |
+
"# setting up google client for making request\n",
|
| 71 |
+
"google_client = genai.Client(\n",
|
| 72 |
+
" api_key=google_api_key\n",
|
| 73 |
+
")\n",
|
| 74 |
+
"\n",
|
| 75 |
+
"response = google_client.models.generate_content(\n",
|
| 76 |
+
" model='gemini-2.5-flash-preview-05-20',\n",
|
| 77 |
+
" contents = \"how won the ipl 2025\"\n",
|
| 78 |
+
")\n",
|
| 79 |
+
"print(response.text)"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"cell_type": "code",
|
| 84 |
+
"execution_count": 7,
|
| 85 |
+
"id": "2a5b91a8",
|
| 86 |
+
"metadata": {},
|
| 87 |
+
"outputs": [],
|
| 88 |
+
"source": [
|
| 89 |
+
"mem_client = MemoryClient(api_key=memo_api_key)"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"cell_type": "code",
|
| 94 |
+
"execution_count": 38,
|
| 95 |
+
"id": "0a33500d",
|
| 96 |
+
"metadata": {},
|
| 97 |
+
"outputs": [],
|
| 98 |
+
"source": [
|
| 99 |
+
"from google import genai\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"client = genai.Client(api_key=google_api_key)\n",
|
| 102 |
+
"\n",
|
| 103 |
+
"my_file = client.files.upload(file=\"/workspaces/ChatBot_with_Long_Term_Memory/AirlineAssisntantAI.png\")\n",
|
| 104 |
+
"\n",
|
| 105 |
+
"response = client.models.generate_content(\n",
|
| 106 |
+
" model=\"gemini-2.0-flash\",\n",
|
| 107 |
+
" contents=[my_file, \"Your Job is to create a base context for the short story based on what you understand from the image and make the story context as close to the image's discription as possible. Also describe what do you understand just by looking at the picture in the description, and make sure to return the result in the json format.\"],\n",
|
| 108 |
+
" config={\n",
|
| 109 |
+
" \"response_mime_type\": \"application/json\",\n",
|
| 110 |
+
" # \"response_schema\": list[Recipe],\n",
|
| 111 |
+
" },\n",
|
| 112 |
+
")\n",
|
| 113 |
+
"\n",
|
| 114 |
+
"json_res = response.text"
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"cell_type": "code",
|
| 119 |
+
"execution_count": 43,
|
| 120 |
+
"id": "bb5a44a4",
|
| 121 |
+
"metadata": {},
|
| 122 |
+
"outputs": [
|
| 123 |
+
{
|
| 124 |
+
"name": "stdout",
|
| 125 |
+
"output_type": "stream",
|
| 126 |
+
"text": [
|
| 127 |
+
"{\n",
|
| 128 |
+
" \"context\": \"The image depicts an 'Airline Ticketing Assistant', suggesting a digital interface designed to help users find information about flight ticket prices. The interface has a chatbot feature, inviting users to ask about ticket prices for cities like London, Paris, or Berlin. A text input field is visible at the bottom where users can type their queries. The interface appears to be built with Gradio and offers access via API, along with settings options.\",\n",
|
| 129 |
+
" \"visual_description\": \"The interface has a dark theme with a title 'Airline Ticketing Assistant'. There is a prompt for the user to ask about ticket prices for London, Paris, or Berlin. There is a 'Chatbot' feature indicated by an icon. The main part of the application is empty where the chat messages would appear. At the bottom is a text input box and a send button. The bottom also includes the links of 'Use via API', 'Built with Gradio', and 'Settings'.\"\n",
|
| 130 |
+
"}\n"
|
| 131 |
+
]
|
| 132 |
+
}
|
| 133 |
+
],
|
| 134 |
+
"source": [
|
| 135 |
+
"print(json_res)"
|
| 136 |
+
]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"cell_type": "code",
|
| 140 |
+
"execution_count": 46,
|
| 141 |
+
"id": "d9e3f4c0",
|
| 142 |
+
"metadata": {},
|
| 143 |
+
"outputs": [],
|
| 144 |
+
"source": [
|
| 145 |
+
"context = json.loads(json_res)['context']"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"cell_type": "code",
|
| 150 |
+
"execution_count": 50,
|
| 151 |
+
"id": "8e27ec1c",
|
| 152 |
+
"metadata": {},
|
| 153 |
+
"outputs": [],
|
| 154 |
+
"source": [
|
| 155 |
+
"story = client.models.generate_content(\n",
|
| 156 |
+
" model='gemini-2.0-flash',\n",
|
| 157 |
+
" contents = f'You are a very good short story teller, when you are given with the context where you try to create a story based on human prospective, now create a very short story based on the given context. context is : {context}'\n",
|
| 158 |
+
")"
|
| 159 |
+
]
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"cell_type": "code",
|
| 163 |
+
"execution_count": 51,
|
| 164 |
+
"id": "dcb0804b",
|
| 165 |
+
"metadata": {},
|
| 166 |
+
"outputs": [
|
| 167 |
+
{
|
| 168 |
+
"data": {
|
| 169 |
+
"text/markdown": [
|
| 170 |
+
"The flickering screen of my laptop illuminated my face, a pale reflection in the late-night glow. It was always the same β endless lines of code, late-night coffee, and the constant, gnawing pressure to perfect her. I called her Astrid.\n",
|
| 171 |
+
"\n",
|
| 172 |
+
"Astrid wasn't a woman, not really. She was an Airline Ticketing Assistant, a chatbot built on Gradio, ready to field questions about the labyrinthine world of flight prices. London, Paris, Berlin β these were the digital destinations she offered, the digital stepping stones to real-world adventures.\n",
|
| 173 |
+
"\n",
|
| 174 |
+
"I imagined the faces behind the queries: the student dreaming of a semester abroad, the businessman chasing a deal, the daughter desperate to see her mother across the ocean. Each question was a tiny spark of hope, of longing, a desire to bridge the gap between here and there.\n",
|
| 175 |
+
"\n",
|
| 176 |
+
"I typed in, \"What's the best price for a round trip to Paris next month?\" pretending to be a user. Astrid responded instantly, a polite, efficient answer flashing across the screen. But I knew it was just data, algorithms at play.\n",
|
| 177 |
+
"\n",
|
| 178 |
+
"My goal was to give her more, to imbue her with empathy, to make her understand the unspoken hopes behind the simple question. How to teach her the anticipation, the anxiety, the raw, vulnerable human need to connect?\n",
|
| 179 |
+
"\n",
|
| 180 |
+
"Tonight, though, she was just code, and I was just a programmer, staring at a screen, chasing the ghost of human connection in the digital ether. Maybe tomorrow, I thought, maybe tomorrow I can make her feel something real. But tonight, all I could offer was data, and a silent, lonely wish.\n"
|
| 181 |
+
],
|
| 182 |
+
"text/plain": [
|
| 183 |
+
"<IPython.core.display.Markdown object>"
|
| 184 |
+
]
|
| 185 |
+
},
|
| 186 |
+
"execution_count": 51,
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"output_type": "execute_result"
|
| 189 |
+
}
|
| 190 |
+
],
|
| 191 |
+
"source": [
|
| 192 |
+
"Markdown(story.text)"
|
| 193 |
+
]
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"cell_type": "code",
|
| 197 |
+
"execution_count": null,
|
| 198 |
+
"id": "188f4ade",
|
| 199 |
+
"metadata": {},
|
| 200 |
+
"outputs": [],
|
| 201 |
+
"source": []
|
| 202 |
+
}
|
| 203 |
+
],
|
| 204 |
+
"metadata": {
|
| 205 |
+
"kernelspec": {
|
| 206 |
+
"display_name": "venv",
|
| 207 |
+
"language": "python",
|
| 208 |
+
"name": "python3"
|
| 209 |
+
},
|
| 210 |
+
"language_info": {
|
| 211 |
+
"codemirror_mode": {
|
| 212 |
+
"name": "ipython",
|
| 213 |
+
"version": 3
|
| 214 |
+
},
|
| 215 |
+
"file_extension": ".py",
|
| 216 |
+
"mimetype": "text/x-python",
|
| 217 |
+
"name": "python",
|
| 218 |
+
"nbconvert_exporter": "python",
|
| 219 |
+
"pygments_lexer": "ipython3",
|
| 220 |
+
"version": "3.12.1"
|
| 221 |
+
}
|
| 222 |
+
},
|
| 223 |
+
"nbformat": 4,
|
| 224 |
+
"nbformat_minor": 5
|
| 225 |
+
}
|
README.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.34.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Story_teller
|
| 3 |
+
app_file: appV01_gradio.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 5.34.0
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
+
# ChatBot_with_Long_Term_Memory
|
| 8 |
+
Creating a simple Chatbot using Long term memory with Mem0
|
appV01.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. imports
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
from mem0 import MemoryClient, Memory
|
| 6 |
+
from google import genai
|
| 7 |
+
|
| 8 |
+
# Intializations
|
| 9 |
+
load_dotenv()
|
| 10 |
+
google_api_key = os.getenv('GOOGLE_API_KEY')
|
| 11 |
+
mem_api_key = os.getenv('MEM_API_KEY')
|
| 12 |
+
|
| 13 |
+
mem_memoryClient = MemoryClient(api_key=mem_api_key)
|
| 14 |
+
google_client = genai.Client(api_key=google_api_key)
|
| 15 |
+
|
| 16 |
+
def google_image_desc_context(file_path):
|
| 17 |
+
sys_prompt = "You a are very talented stroyteller who can create a amazing, attention grabing stories just by looking at the picture, Your main task as a storyteller is to give best context for a story so that another model can generate seemlessly"
|
| 18 |
+
sys_prompt += "Your main 2 task is to give 1. complete discription of the image 2. give the base context as well as ending context for the story."
|
| 19 |
+
sys_prompt += "You will always return the response in the json format:"
|
| 20 |
+
sys_prompt += """
|
| 21 |
+
{
|
| 22 |
+
"story_context": 'here we will have the context for the story',
|
| 23 |
+
"image_description": "here we will have the complete description for the story"
|
| 24 |
+
}
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
my_file = google_client.files.upload(file=file_path)
|
| 28 |
+
|
| 29 |
+
res = google_client.models.generate_content(
|
| 30 |
+
model='gemini-2.0-flash',
|
| 31 |
+
contents = [my_file, sys_prompt],
|
| 32 |
+
config={
|
| 33 |
+
"response_mime_type": "application/json",
|
| 34 |
+
# "response_schema": list[Recipe],
|
| 35 |
+
},
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
return json.loads(res.text)
|
| 39 |
+
|
| 40 |
+
json_data = google_image_desc_context("/workspaces/ChatBot_with_Long_Term_Memory/AirlineAssisntantAI.png")
|
| 41 |
+
print(json_data['image_description'])
|
| 42 |
+
print(json_data['story_context'])
|
| 43 |
+
|
| 44 |
+
def story_teller(context):
|
| 45 |
+
res = google_client.models.generate_content(
|
| 46 |
+
model = 'gemini-2.0-flash',
|
| 47 |
+
contents = f"You are a very good story teller, who can create a attention grabing story just with the use of context, Your job is to create a story based on the provived context as this {context}, create a story within 150 words"
|
| 48 |
+
)
|
| 49 |
+
return res.text
|
| 50 |
+
print("---"*50)
|
| 51 |
+
print(story_teller(json_data['story_context']))
|
| 52 |
+
|
| 53 |
+
from google import genai
|
| 54 |
+
from google.genai import types
|
| 55 |
+
import wave
|
| 56 |
+
|
| 57 |
+
# Set up the wave file to save the output:
|
| 58 |
+
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
|
| 59 |
+
with wave.open(filename, "wb") as wf:
|
| 60 |
+
wf.setnchannels(channels)
|
| 61 |
+
wf.setsampwidth(sample_width)
|
| 62 |
+
wf.setframerate(rate)
|
| 63 |
+
wf.writeframes(pcm)
|
| 64 |
+
|
| 65 |
+
client = genai.Client(api_key=google_api_key)
|
| 66 |
+
|
| 67 |
+
response = client.models.generate_content(
|
| 68 |
+
model="gemini-2.5-flash-preview-tts",
|
| 69 |
+
contents=story_teller(json_data['story_context']),
|
| 70 |
+
config=types.GenerateContentConfig(
|
| 71 |
+
response_modalities=["AUDIO"],
|
| 72 |
+
speech_config=types.SpeechConfig(
|
| 73 |
+
voice_config=types.VoiceConfig(
|
| 74 |
+
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|
| 75 |
+
voice_name='Kore',
|
| 76 |
+
)
|
| 77 |
+
)
|
| 78 |
+
),
|
| 79 |
+
)
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
data = response.candidates[0].content.parts[0].inline_data.data
|
| 83 |
+
|
| 84 |
+
file_name='out.wav'
|
| 85 |
+
wave_file(file_name, data) # Saves the file to current directory
|
appV01_gradio.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
|
| 10 |
+
# Set up logging
|
| 11 |
+
logging.basicConfig(level=logging.INFO)
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
# Try importing required libraries with error handling
|
| 15 |
+
try:
|
| 16 |
+
from mem0 import MemoryClient, Memory
|
| 17 |
+
MEM0_AVAILABLE = True
|
| 18 |
+
except ImportError:
|
| 19 |
+
logger.warning("mem0 library not available. Memory features will be disabled.")
|
| 20 |
+
MEM0_AVAILABLE = False
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
from google import genai
|
| 24 |
+
from google.genai import types
|
| 25 |
+
GOOGLE_AI_AVAILABLE = True
|
| 26 |
+
except ImportError:
|
| 27 |
+
logger.error("Google AI library not available. Please install google-generativeai")
|
| 28 |
+
GOOGLE_AI_AVAILABLE = False
|
| 29 |
+
|
| 30 |
+
class StorytellingApp:
|
| 31 |
+
def __init__(self):
|
| 32 |
+
self.setup_environment()
|
| 33 |
+
self.initialize_clients()
|
| 34 |
+
|
| 35 |
+
def setup_environment(self):
|
| 36 |
+
"""Load environment variables"""
|
| 37 |
+
try:
|
| 38 |
+
load_dotenv()
|
| 39 |
+
self.google_api_key = os.getenv('GOOGLE_API_KEY')
|
| 40 |
+
self.mem_api_key = os.getenv('MEM_API_KEY')
|
| 41 |
+
|
| 42 |
+
if not self.google_api_key:
|
| 43 |
+
raise ValueError("GOOGLE_API_KEY not found in environment variables")
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
logger.error(f"Environment setup failed: {e}")
|
| 47 |
+
raise
|
| 48 |
+
|
| 49 |
+
def initialize_clients(self):
|
| 50 |
+
"""Initialize API clients"""
|
| 51 |
+
try:
|
| 52 |
+
if not GOOGLE_AI_AVAILABLE:
|
| 53 |
+
raise ImportError("Google AI library not available")
|
| 54 |
+
|
| 55 |
+
self.google_client = genai.Client(api_key=self.google_api_key)
|
| 56 |
+
|
| 57 |
+
# Initialize memory client if available
|
| 58 |
+
if MEM0_AVAILABLE and self.mem_api_key:
|
| 59 |
+
self.mem_client = MemoryClient(api_key=self.mem_api_key)
|
| 60 |
+
else:
|
| 61 |
+
self.mem_client = None
|
| 62 |
+
logger.warning("Memory client not initialized")
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
logger.error(f"Client initialization failed: {e}")
|
| 66 |
+
raise
|
| 67 |
+
|
| 68 |
+
def google_image_desc_context(self, file_path: str) -> dict:
|
| 69 |
+
"""Extract story context and description from image"""
|
| 70 |
+
try:
|
| 71 |
+
if not os.path.exists(file_path):
|
| 72 |
+
raise FileNotFoundError(f"Image file not found: {file_path}")
|
| 73 |
+
|
| 74 |
+
sys_prompt = """You are a very talented storyteller who can create amazing, attention-grabbing stories just by looking at pictures.
|
| 75 |
+
Your main task as a storyteller is to give the best context for a story so that another model can generate seamlessly.
|
| 76 |
+
|
| 77 |
+
Your main 2 tasks are to give:
|
| 78 |
+
1. Complete description of the image
|
| 79 |
+
2. Give the base context as well as ending context for the story
|
| 80 |
+
|
| 81 |
+
You will always return the response in JSON format:
|
| 82 |
+
{
|
| 83 |
+
"story_context": "here we will have the context for the story",
|
| 84 |
+
"image_description": "here we will have the complete description of the image"
|
| 85 |
+
}"""
|
| 86 |
+
|
| 87 |
+
# Upload file to Google AI
|
| 88 |
+
my_file = self.google_client.files.upload(file=file_path)
|
| 89 |
+
|
| 90 |
+
# Generate content
|
| 91 |
+
response = self.google_client.models.generate_content(
|
| 92 |
+
model='gemini-2.0-flash',
|
| 93 |
+
contents=[my_file, sys_prompt],
|
| 94 |
+
config={
|
| 95 |
+
"response_mime_type": "application/json",
|
| 96 |
+
},
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
result = json.loads(response.text)
|
| 100 |
+
|
| 101 |
+
# Validate response structure
|
| 102 |
+
if 'story_context' not in result or 'image_description' not in result:
|
| 103 |
+
raise ValueError("Invalid response format from AI model")
|
| 104 |
+
|
| 105 |
+
return result
|
| 106 |
+
|
| 107 |
+
except json.JSONDecodeError as e:
|
| 108 |
+
logger.error(f"JSON parsing error: {e}")
|
| 109 |
+
raise ValueError("Failed to parse AI response")
|
| 110 |
+
except Exception as e:
|
| 111 |
+
logger.error(f"Image analysis failed: {e}")
|
| 112 |
+
raise
|
| 113 |
+
|
| 114 |
+
def story_teller(self, context: str) -> str:
|
| 115 |
+
"""Generate story from context"""
|
| 116 |
+
try:
|
| 117 |
+
if not context or not context.strip():
|
| 118 |
+
raise ValueError("Context cannot be empty")
|
| 119 |
+
|
| 120 |
+
prompt = f"""You are a very good storyteller who can create attention-grabbing stories just with the use of context.
|
| 121 |
+
Your job is to create a story based on the provided context: {context}
|
| 122 |
+
Create a story within 150 words that is engaging and complete."""
|
| 123 |
+
|
| 124 |
+
response = self.google_client.models.generate_content(
|
| 125 |
+
model='gemini-2.0-flash',
|
| 126 |
+
contents=prompt
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
if not response.text:
|
| 130 |
+
raise ValueError("Empty response from story generation")
|
| 131 |
+
|
| 132 |
+
return response.text.strip()
|
| 133 |
+
|
| 134 |
+
except Exception as e:
|
| 135 |
+
logger.error(f"Story generation failed: {e}")
|
| 136 |
+
raise
|
| 137 |
+
|
| 138 |
+
def create_audio_story(self, story_text: str) -> str:
|
| 139 |
+
"""Convert story text to audio"""
|
| 140 |
+
try:
|
| 141 |
+
if not story_text or not story_text.strip():
|
| 142 |
+
raise ValueError("Story text cannot be empty")
|
| 143 |
+
|
| 144 |
+
response = self.google_client.models.generate_content(
|
| 145 |
+
model="gemini-2.5-flash-preview-tts",
|
| 146 |
+
contents=story_text,
|
| 147 |
+
config=types.GenerateContentConfig(
|
| 148 |
+
response_modalities=["AUDIO"],
|
| 149 |
+
speech_config=types.SpeechConfig(
|
| 150 |
+
voice_config=types.VoiceConfig(
|
| 151 |
+
prebuilt_voice_config=types.PrebuiltVoiceConfig(
|
| 152 |
+
voice_name='Kore',
|
| 153 |
+
)
|
| 154 |
+
)
|
| 155 |
+
),
|
| 156 |
+
)
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
if not response.candidates or not response.candidates[0].content.parts:
|
| 160 |
+
raise ValueError("No audio data received from TTS service")
|
| 161 |
+
|
| 162 |
+
audio_data = response.candidates[0].content.parts[0].inline_data.data
|
| 163 |
+
|
| 164 |
+
# Create temporary file for audio
|
| 165 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
|
| 166 |
+
self.save_wave_file(temp_file.name, audio_data)
|
| 167 |
+
|
| 168 |
+
return temp_file.name
|
| 169 |
+
|
| 170 |
+
except Exception as e:
|
| 171 |
+
logger.error(f"Audio generation failed: {e}")
|
| 172 |
+
raise
|
| 173 |
+
|
| 174 |
+
def save_wave_file(self, filename: str, pcm_data: bytes, channels: int = 1,
|
| 175 |
+
rate: int = 24000, sample_width: int = 2):
|
| 176 |
+
"""Save PCM data as WAV file"""
|
| 177 |
+
try:
|
| 178 |
+
with wave.open(filename, "wb") as wf:
|
| 179 |
+
wf.setnchannels(channels)
|
| 180 |
+
wf.setsampwidth(sample_width)
|
| 181 |
+
wf.setframerate(rate)
|
| 182 |
+
wf.writeframes(pcm_data)
|
| 183 |
+
except Exception as e:
|
| 184 |
+
logger.error(f"Wave file creation failed: {e}")
|
| 185 |
+
raise
|
| 186 |
+
|
| 187 |
+
def process_image_to_story(self, image_file) -> Tuple[str, str, str, Optional[str]]:
|
| 188 |
+
"""Main processing function for Gradio interface"""
|
| 189 |
+
try:
|
| 190 |
+
if image_file is None:
|
| 191 |
+
return "β Error: Please upload an image", "", "", None
|
| 192 |
+
|
| 193 |
+
# Analyze image
|
| 194 |
+
try:
|
| 195 |
+
analysis_result = self.google_image_desc_context(image_file)
|
| 196 |
+
image_description = analysis_result['image_description']
|
| 197 |
+
story_context = analysis_result['story_context']
|
| 198 |
+
except Exception as e:
|
| 199 |
+
return f"β Image analysis failed: {str(e)}", "", "", None
|
| 200 |
+
|
| 201 |
+
# Generate story
|
| 202 |
+
try:
|
| 203 |
+
story_text = self.story_teller(story_context)
|
| 204 |
+
except Exception as e:
|
| 205 |
+
return f"β Story generation failed: {str(e)}", image_description, story_context, None
|
| 206 |
+
|
| 207 |
+
# Generate audio
|
| 208 |
+
try:
|
| 209 |
+
audio_file = self.create_audio_story(story_text)
|
| 210 |
+
return "β
Story generated successfully!", image_description, story_context, story_text, audio_file
|
| 211 |
+
except Exception as e:
|
| 212 |
+
logger.warning(f"Audio generation failed: {e}")
|
| 213 |
+
return "β οΈ Story generated but audio creation failed", image_description, story_context, story_text, None
|
| 214 |
+
|
| 215 |
+
except Exception as e:
|
| 216 |
+
logger.error(f"Unexpected error in processing: {e}")
|
| 217 |
+
return f"β Unexpected error: {str(e)}", "", "", None
|
| 218 |
+
|
| 219 |
+
def create_gradio_interface():
|
| 220 |
+
"""Create and configure Gradio interface"""
|
| 221 |
+
try:
|
| 222 |
+
app = StorytellingApp()
|
| 223 |
+
except Exception as e:
|
| 224 |
+
logger.error(f"Failed to initialize app: {e}")
|
| 225 |
+
|
| 226 |
+
# Create a fallback interface that shows the error
|
| 227 |
+
def error_interface(image):
|
| 228 |
+
return f"β Application initialization failed: {str(e)}", "", "", None
|
| 229 |
+
|
| 230 |
+
interface = gr.Interface(
|
| 231 |
+
fn=error_interface,
|
| 232 |
+
inputs=gr.Image(type="filepath", label="Upload Image"),
|
| 233 |
+
outputs=[
|
| 234 |
+
gr.Textbox(label="Status", lines=2),
|
| 235 |
+
gr.Textbox(label="Image Description", lines=3),
|
| 236 |
+
gr.Textbox(label="Story Context", lines=3),
|
| 237 |
+
gr.Audio(label="Story Audio")
|
| 238 |
+
],
|
| 239 |
+
title="π AI Storyteller - Error",
|
| 240 |
+
description="Application failed to initialize. Please check your API keys and dependencies.",
|
| 241 |
+
)
|
| 242 |
+
return interface
|
| 243 |
+
|
| 244 |
+
# Create the main interface
|
| 245 |
+
def process_wrapper(image):
|
| 246 |
+
try:
|
| 247 |
+
return app.process_image_to_story(image)
|
| 248 |
+
except Exception as e:
|
| 249 |
+
logger.error(f"Processing wrapper error: {e}")
|
| 250 |
+
return f"β Processing failed: {str(e)}", "", "", None
|
| 251 |
+
|
| 252 |
+
interface = gr.Interface(
|
| 253 |
+
fn=process_wrapper,
|
| 254 |
+
inputs=[
|
| 255 |
+
gr.Image(
|
| 256 |
+
type="filepath",
|
| 257 |
+
label="πΈ Upload Image",
|
| 258 |
+
height=300
|
| 259 |
+
)
|
| 260 |
+
],
|
| 261 |
+
outputs=[
|
| 262 |
+
gr.Textbox(
|
| 263 |
+
label="π Status",
|
| 264 |
+
lines=2,
|
| 265 |
+
show_copy_button=True
|
| 266 |
+
),
|
| 267 |
+
gr.Textbox(
|
| 268 |
+
label="πΌοΈ Image Description",
|
| 269 |
+
lines=4,
|
| 270 |
+
show_copy_button=True
|
| 271 |
+
),
|
| 272 |
+
gr.Textbox(
|
| 273 |
+
label="π Story Context",
|
| 274 |
+
lines=4,
|
| 275 |
+
show_copy_button=True
|
| 276 |
+
),
|
| 277 |
+
gr.Textbox(
|
| 278 |
+
label="π Generated Story",
|
| 279 |
+
lines=6,
|
| 280 |
+
show_copy_button=True
|
| 281 |
+
),
|
| 282 |
+
gr.Audio(
|
| 283 |
+
label="π΅ Story Audio",
|
| 284 |
+
type="filepath"
|
| 285 |
+
)
|
| 286 |
+
],
|
| 287 |
+
title="π AI Storyteller",
|
| 288 |
+
description="""
|
| 289 |
+
Upload an image and let AI create an amazing story for you!
|
| 290 |
+
|
| 291 |
+
**Features:**
|
| 292 |
+
- π Analyzes your image to understand the scene
|
| 293 |
+
- π Creates engaging story context
|
| 294 |
+
- βοΈ Generates a complete story (150 words)
|
| 295 |
+
- π€ Converts story to speech audio
|
| 296 |
+
|
| 297 |
+
**Requirements:**
|
| 298 |
+
- Valid GOOGLE_API_KEY in your .env file
|
| 299 |
+
- Supported image formats: JPG, PNG, GIF, BMP
|
| 300 |
+
""",
|
| 301 |
+
theme=gr.themes.Soft(),
|
| 302 |
+
css="""
|
| 303 |
+
.gradio-container {
|
| 304 |
+
max-width: 100% !important;
|
| 305 |
+
width: 100% !important;
|
| 306 |
+
}
|
| 307 |
+
.contain {
|
| 308 |
+
max-width: 100% !important;
|
| 309 |
+
}
|
| 310 |
+
""",
|
| 311 |
+
examples=[
|
| 312 |
+
# You can add example images here if you have them
|
| 313 |
+
],
|
| 314 |
+
cache_examples=False,
|
| 315 |
+
allow_flagging="never"
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
return interface
|
| 319 |
+
|
| 320 |
+
if __name__ == "__main__":
|
| 321 |
+
try:
|
| 322 |
+
# Check if required environment variables exist
|
| 323 |
+
load_dotenv()
|
| 324 |
+
if not os.getenv('GOOGLE_API_KEY'):
|
| 325 |
+
print("β Error: GOOGLE_API_KEY not found in environment variables")
|
| 326 |
+
print("Please create a .env file with your Google AI API key")
|
| 327 |
+
exit(1)
|
| 328 |
+
|
| 329 |
+
# Launch the interface
|
| 330 |
+
interface = create_gradio_interface()
|
| 331 |
+
interface.launch(
|
| 332 |
+
server_name="0.0.0.0", # Allow external access
|
| 333 |
+
server_port=7860, # Default Gradio port
|
| 334 |
+
share=False, # Set to True to create public link
|
| 335 |
+
debug=True # Enable debug mode
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
except Exception as e:
|
| 339 |
+
logger.error(f"Failed to launch application: {e}")
|
| 340 |
+
print(f"β Application launch failed: {e}")
|
out.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a6f78e8b4ce40827745944815716776440ff6967a44305b1a576933a827b6c55
|
| 3 |
+
size 2358330
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
openai
|
| 3 |
+
google-genai
|
| 4 |
+
dotenv
|
| 5 |
+
wave
|
| 6 |
+
tempfile
|
| 7 |
+
typing
|
| 8 |
+
logging
|