एआई के दौर में ऐप्लिकेशन बनाना

1. खास जानकारी

इस लैब में, आपको Google के जनरेटिव एआई प्रॉडक्ट का इस्तेमाल करके, Gemini Cloud Assist की मदद से Google Cloud में इन्फ़्रास्ट्रक्चर बनाने के बारे में जानकारी मिलेगी. साथ ही, Data Canvas की एसक्यूएल सुविधाओं की मदद से, सामान्य भाषा का इस्तेमाल करके BigQuery डेटा को क्वेरी करने का तरीका भी बताया जाएगा. इसके अलावा, Gemini Code Assist की मदद से, Colab Enterprise Jupyter नोटबुक और Eclipse Theia (Visual Studio Code) में कोड लिखने का तरीका भी बताया जाएगा. साथ ही, Vertex AI एजेंट बिल्डर में Cloud Storage और BigQuery ग्राउंडिंग सोर्स पर आधारित एआई सर्च और चैट की सुविधाओं को इंटिग्रेट करने का तरीका भी बताया जाएगा.

हमारा लक्ष्य, रेसिपी और खाना बनाने से जुड़ी एक वेबसाइट बनाना है. इसका नाम AI Recipe Haven होगा. यह साइट, Python और Streamlit में बनाई जाएगी. इसमें दो मुख्य पेज होंगे. Cooking Advice में एक चैटबॉट होगा. इसे हम Gemini और Vertex AI एजेंट बिल्डर का इस्तेमाल करके बनाएंगे. यह चैटबॉट, कुकबुक के ग्रुप से जुड़े सोर्स पर आधारित होगा. यह चैटबॉट, खाना बनाने से जुड़ी सलाह देगा और इस बारे में पूछे जाने वाले सवालों के जवाब देगा. Recipe Search एक ऐसा सर्च इंजन होगा जिसे Gemini से फ़ीड किया जाएगा. इस बार, यह BigQuery के रेसिपी डेटाबेस पर आधारित होगा.

अगर आपको इस एक्सरसाइज़ में किसी कोड में समस्या आती है, तो सभी कोड फ़ाइलों के समाधान, एक्सरसाइज़ के GitHub रिपॉज़िटरी में solution शाखा में मौजूद हैं.

मकसद

इस लैब में, आपको ये काम करने का तरीका पता चलेगा:

  • Gemini Cloud Assist को चालू और इस्तेमाल करना
  • खाना बनाने से जुड़ी सलाह देने वाले चैटबॉट के लिए, Vertex AI Agent Builder में खोज ऐप्लिकेशन बनाना
  • Gemini Code Assist की मदद से, Colab Enterprise के नोटबुक में डेटा लोड करना और उसे क्लीन करना
  • रेसिपी जनरेटर के लिए, Vertex AI Agent Builder में सर्च ऐप्लिकेशन बनाना
  • Gemini की मदद से, Python और Streamlit के मुख्य वेब ऐप्लिकेशन को फ़्रेम करना
  • वेब ऐप्लिकेशन को Cloud Run पर डिप्लॉय करना
  • कुकिंग सलाह वाले पेज को, कुकबुक खोजने वाले एजेंट बिल्डर ऐप्लिकेशन से कनेक्ट करना
  • (ज़रूरी नहीं) रेसिपी खोज पेज को रेसिपी खोजने वाले एजेंट बिल्डर ऐप्लिकेशन से कनेक्ट करना
  • (ज़रूरी नहीं) फ़ाइनल ऐप्लिकेशन एक्सप्लोर करना

2. सेटअप और ज़रूरी शर्तें

'लैब शुरू करें' बटन पर क्लिक करने से पहले

ये निर्देश पढ़ें. Labs में एक्सपेरिमेंट के लिए तय समय होता है. इसे बीच में नहीं रोका जा सकता. 'लैब शुरू करें' पर क्लिक करने के बाद दिखने वाला टाइमर, यह बताता है कि Google Cloud के संसाधन आपको कितने समय तक उपलब्ध कराए जाएंगे.

Qwiklabs के इस लैब में, लैब की गतिविधियां खुद की जा सकती हैं. इसके लिए, आपको सिम्युलेशन या डेमो वाले माहौल के बजाय, असल क्लाउड एनवायरमेंट का इस्तेमाल करना होगा. यह आपको नए और कुछ समय के लिए मान्य क्रेडेंशियल देता है. इनका इस्तेमाल करके, लैब के दौरान Google Cloud में साइन इन किया जा सकता है और उसे ऐक्सेस किया जा सकता है.

आपको इन चीज़ों की ज़रूरत पड़ेगी

इस लैब को पूरा करने के लिए, आपको ये चीज़ें चाहिए:

  • स्टैंडर्ड इंटरनेट ब्राउज़र का ऐक्सेस (हमारा सुझाव है कि आप Chrome ब्राउज़र का इस्तेमाल करें).
  • लैब पूरा करने में लगने वाला समय.

ध्यान दें: अगर आपके पास पहले से ही निजी Google Cloud खाता या प्रोजेक्ट है, तो इस लैब के लिए उसका इस्तेमाल न करें.

ध्यान दें: अगर Pixelbook का इस्तेमाल किया जा रहा है, तो इस लैब को चलाने के लिए गुप्त विंडो खोलें.

अपना लैब शुरू करने और Google Cloud Console में साइन इन करने का तरीका

  1. 'लैब शुरू करें' बटन पर क्लिक करें. अगर आपको लैब के लिए पैसे चुकाने हैं, तो पेमेंट का तरीका चुनने के लिए एक पॉप-अप खुलेगा. बाईं ओर एक पैनल है, जिसमें कुछ समय के लिए दिए गए क्रेडेंशियल दिखते हैं. आपको इस लैब के लिए इनका इस्तेमाल करना होगा.

52e0878388c0d9ed.png

  1. उपयोगकर्ता नाम कॉपी करें. इसके बाद, 'Google Console खोलें' पर क्लिक करें. लैब, संसाधनों को चालू करता है और फिर एक और टैब खोलता है, जिसमें साइन इन पेज दिखता है.

2a4b7165afebf5ab.png

सलाह: टैब को अलग-अलग विंडो में, एक साथ खोलें.

अगर आपको 'कोई खाता चुनें' पेज दिखता है, तो 'कोई दूसरा खाता इस्तेमाल करें' पर क्लिक करें.

6463aa9b492a3b60.png

  1. साइन इन करें पेज पर, कनेक्शन की जानकारी वाले पैनल से कॉपी किया गया उपयोगकर्ता नाम चिपकाएं. इसके बाद, पासवर्ड कॉपी करके चिपकाएं.

अहम जानकारी: आपको कनेक्शन की जानकारी वाले पैनल में दिए गए क्रेडेंशियल का इस्तेमाल करना होगा. अपने Qwiklabs क्रेडेंशियल का इस्तेमाल न करें. अगर आपके पास अपना Google Cloud खाता है, तो इस लैब के लिए उसका इस्तेमाल न करें. इससे आपको शुल्क नहीं देना पड़ेगा. 4. अगले पेजों पर क्लिक करें:

  1. नियम और शर्तें स्वीकार करें.
  2. खाता वापस पाने के विकल्प या दो-फ़ैक्टर पुष्टि की सुविधा न जोड़ें, क्योंकि यह एक अस्थायी खाता है.
  3. मुफ़्त में आज़माने की सुविधा के लिए साइन अप न करें.

कुछ देर बाद, Cloud Console इस टैब में खुल जाएगा.

ध्यान दें: Google Cloud के प्रॉडक्ट और सेवाओं की सूची वाला मेन्यू देखने के लिए, सबसे ऊपर बाईं ओर मौजूद नेविगेशन मेन्यू पर क्लिक करें.

bbdc8ea800bf0adc.png

3. टास्क 0. अपना वर्कस्टेशन क्लस्टर देखना

इस लैब के आखिरी हिस्से में, आपको कुछ डेवलपमेंट का काम करने के लिए Google Cloud Workstation का इस्तेमाल करना होगा. इस लैब के शुरू होने की प्रोसेस से, आपके वर्कस्टेशन का क्लस्टर बनना शुरू हो जाना चाहिए. आगे बढ़ने से पहले, यह पक्का कर लें कि क्लस्टर बन रहा है.

  1. Google Cloud Console में, खोज बॉक्स का इस्तेमाल करके Cloud Workstations पर जाएं.
  2. क्लस्टर मैनेजमेंट देखने के लिए, बाईं ओर मौजूद नेविगेशन मेन्यू का इस्तेमाल करें.
  3. अगर आपका क्लस्टर अपडेट हो रहा है, तो आपके पास टास्क 1 पर जाने का विकल्प है. अगर आपको किसी भी स्थिति में कोई क्लस्टर नहीं दिखता है, तो पेज को रीफ़्रेश करें. अगर आपको अब भी क्लस्टर अपडेट हो रहा है (बन रहा है) नहीं दिखता है, तो इन निर्देशों के ऊपर बाईं ओर मौजूद बटन का इस्तेमाल करके, इस लैब को बंद करें और लैब को फिर से शुरू करें.

4. पहला टास्क. Gemini Cloud Assist को चालू और इस्तेमाल करना

इस टास्क में, हम Gemini Cloud Assist को चालू और इस्तेमाल करेंगे. Google Cloud Console में काम करते समय, Gemini Cloud Assist आपको सलाह दे सकता है. साथ ही, Google Cloud इंफ़्रास्ट्रक्चर को बनाने, कॉन्फ़िगर करने, और उसकी निगरानी करने में आपकी मदद कर सकता है. यह gcloud निर्देशों का सुझाव भी दे सकता है और Terraform स्क्रिप्ट लिख सकता है.

  1. Cloud Assist का इस्तेमाल करने के लिए, Cloud Console के यूज़र इंटरफ़ेस (यूआई) में सबसे ऊपर मौजूद खोज बॉक्स में क्लिक करें. इसके बाद, Gemini से पूछें को चुनें. इसके अलावा, Cloud Console के लिए Gemini से पूछें को भी चुना जा सकता है.
  2. पेज पर ज़रूरी एपीआई सेक्शन तक स्क्रोल करें और Gemini for Google Cloud API को चालू करें.
  3. अगर आपको तुरंत चैट इंटरफ़ेस नहीं दिखता है, तो चैट शुरू करें पर क्लिक करें. Gemini से Cloud Workstations का इस्तेमाल करने के कुछ फ़ायदे बताने के लिए कहें. जनरेट किए गए जवाब को देखने के लिए कुछ समय निकालें.
  4. इसके बाद, एजेंट बिल्डर के फ़ायदों के बारे में पूछें. साथ ही, यह भी जानें कि यह जनरेटिव जवाबों को बेहतर बनाने में कैसे मदद कर सकता है.
  5. आखिर में, इन दोनों के बीच तुलना करते हैं. Google Cloud Console की Gemini चैट विंडो में, यह सवाल पूछें:
What are the major steps to creating a search app grounded in a
GCS data source using Vertex AI Agent builder?
  1. अब, गुप्त विंडो के बजाय सामान्य विंडो में, Gemini की सार्वजनिक वेबसाइट पर जाएं. इसके बाद, ज़रूरत पड़ने पर लॉग इन करें और वही सवाल पूछें. क्या जवाब एक जैसे हैं या कम से कम मिलते-जुलते हैं? इसके लिए क्या करना होगा? क्या इनमें से कोई एक विकल्प बेहतर है? इसके बावजूद, अगले चरणों को पूरा करते समय, इन जवाबों को ध्यान में रखें.

ध्यान दें: अगर ऊपर दिया गया तरीका, Qwiklabs के अपने अस्थायी खाते का इस्तेमाल करके आज़माया जाता है, तो आपको ब्लॉक कर दिया जाएगा. अगर आपका ऑफ़िस खाता भी ब्लॉक है, क्योंकि आपका संगठन Gemini के वेब ऐप्लिकेशन का इस्तेमाल करने की अनुमति नहीं दे रहा है, तो इस चरण को छोड़ दें और आगे बढ़ें. इससे, इस एक्सरसाइज़ को पूरा करने की आपकी क्षमता पर कोई असर नहीं पड़ेगा.

5. दूसरा टास्क. खाना बनाने से जुड़ी सलाह देने वाले चैटबॉट के लिए, Vertex AI Agent Builder में खोज ऐप्लिकेशन बनाना

हम जिस वेबसाइट को बना रहे हैं उसमें खाना बनाने से जुड़ी सलाह देने वाला पेज होगा. इस पेज पर एक चैटबॉट भी होगा, जिसे खाना बनाने से जुड़े सवालों के जवाब देने के लिए डिज़ाइन किया गया है. यह Gemini की मदद से काम करेगा. इसमें सार्वजनिक डोमेन की 70 कुकबुक का डेटा शामिल होगा. कुकबुक, Gemini के लिए सटीक जानकारी का सोर्स होंगी. Gemini, सवालों के जवाब देने के लिए इनका इस्तेमाल करता है.

  1. Vertex AI पर जाने के लिए, Cloud Console के खोज बॉक्स का इस्तेमाल करें. डैशबोर्ड में, सुझाए गए सभी एपीआई चालू करें पर क्लिक करें. अगर आपको Vertex AI API को चालू करने के बारे में पॉप-अप बॉक्स मिलता है, तो कृपया उसे भी चालू करें.
  2. खोज का इस्तेमाल करके, एजेंट बिल्डर पर जाएं. इसके बाद, जारी रखें और एपीआई चालू करें पर क्लिक करें.
  3. जैसा कि Gemini ने हमारी पिछली सलाह में सुझाया था कि Agent Builder में सर्च ऐप्लिकेशन बनाने के लिए, सबसे पहले आधिकारिक डेटा सोर्स बनाना ज़रूरी है. जब कोई उपयोगकर्ता कुछ खोजता है, तो Gemini उस सवाल को समझता है और बेहतर जवाब देने का तरीका भी समझता है. हालांकि, वह जवाब में इस्तेमाल की जाने वाली जानकारी के लिए, अपने अंदर मौजूद जानकारी का इस्तेमाल करने के बजाय, किसी भरोसेमंद सोर्स का इस्तेमाल करता है.

बाईं ओर मौजूद मेन्यू में, डेटा स्टोर पर जाएं और डेटा स्टोर बनाएं. 4. खाना बनाने से जुड़ी सलाह देने वाले पेज पर, सार्वजनिक डोमेन की जिन कुकबुक का इस्तेमाल किया जा रहा है वे फ़िलहाल किसी बाहरी प्रोजेक्ट की Cloud Storage बकेट में मौजूद हैं. Cloud Storage का सोर्स टाइप चुनें. 5. इंपोर्ट की जा रही जानकारी के टाइप से जुड़े डिफ़ॉल्ट विकल्पों की जांच करें, लेकिन उन्हें न बदलें. इंपोर्ट टाइप को फ़ोल्डर पर सेट रहने दें और बकेट पाथ के लिए: labs.roitraining.com/labs/old-cookbooks का इस्तेमाल करें. इसके बाद, जारी रखें पर क्लिक करें. 6. डेटा स्टोर को नाम दें: old-cookbooks. बदलाव करें और आईडी को old-cookbooks-id में बदलें. इसके बाद, डेटा स्टोर बनाएं.

Vertex AI Agent Builder, कई तरह के ऐप्लिकेशन के साथ काम करता है. साथ ही, डेटा स्टोर हर ऐप्लिकेशन के लिए सटीक जानकारी का सोर्स होता है. खोज ऐप्लिकेशन, सामान्य इस्तेमाल और खोज के लिए अच्छे होते हैं. चैट ऐप्लिकेशन, डेटाफ़्लो से चलने वाले चैटबॉट/वॉइसबॉट ऐप्लिकेशन में जनरेटिव फ़्लो के लिए होते हैं. सुझाव देने वाले ऐप्लिकेशन, सुझाव देने वाले बेहतर इंजन बनाने में मदद करते हैं. साथ ही, एजेंट ऐप्लिकेशन, जनरेटिव एआई से चलने वाले एजेंट बनाने के लिए हैं. आखिरकार, एजेंट की मदद से, हम अपनी ज़रूरत के हिसाब से काम कर पाएंगे. हालांकि, फ़िलहाल प्रीव्यू में मौजूद प्रॉडक्ट के लिए, हम Search Network में दिखने वाले ऐप्लिकेशन का ही इस्तेमाल करेंगे. 7. बाईं ओर मौजूद मेन्यू का इस्तेमाल करके, ऐप्लिकेशन पर जाएं. इसके बाद, ऐप्लिकेशन बनाएं पर क्लिक करें. 8. Search Network में दिखने वाले ऐप्लिकेशन का टाइप चुनें. अलग-अलग विकल्पों की जांच करें, लेकिन उन्हें न बदलें. ऐप्लिकेशन का नाम: cookbook-search. बदलाव करें और ऐप्लिकेशन आईडी को cookbook-search-id पर सेट करें. कंपनी को Google पर सेट करें और जारी रखें पर क्लिक करें. 9. वह old-cookbooks डेटा स्टोर देखें जिसे आपने कुछ ही चरण पहले बनाया था. इसके बाद, Search ऐप्लिकेशन बनाएं.

गतिविधि टैब की जांच करने पर, आपको पता चलेगा कि कुकबुक अब भी इंपोर्ट और इंडेक्स हो रही हैं. Agent Builder को, हमने 70 कुकबुक दी हैं. इनमें मौजूद हज़ारों पेजों को इंडेक्स करने में, उसे पांच मिनट से ज़्यादा का समय लगेगा. इस प्रोसेस के दौरान, आइए अपने रेसिपी जनरेटर के लिए, रेसिपी डेटाबेस का कुछ डेटा लोड और क्लीन करते हैं.

6. तीसरा टास्क. Gemini Code Assist की मदद से, Colab Enterprise के नोटबुक में डेटा लोड करना और उसे क्लीन करना

Google Cloud, Jupiter नोटबुक के साथ काम करने के कुछ मुख्य तरीके उपलब्ध कराता है. हम Google की नई सुविधा, Colab Enterprise का इस्तेमाल करने जा रहे हैं. आप में से कुछ लोगों को Google के Colab प्रॉडक्ट के बारे में पता होगा. इसका इस्तेमाल आम तौर पर वे लोग और संगठन करते हैं जो बिना किसी शुल्क के Jupiter नोटबुक आज़माना चाहते हैं. Colab Enterprise, Google Cloud की एक कमर्शियल सेवा है. यह Google के अन्य क्लाउड प्रॉडक्ट के साथ पूरी तरह से इंटिग्रेट है. साथ ही, यह GCP एनवायरमेंट की सुरक्षा और नियमों का पालन करने से जुड़ी सुविधाओं का पूरा फ़ायदा लेती है.

Colab Enterprise की एक सुविधा, Google के Gemini Code Assist के साथ इंटिग्रेशन है. कोड असिस्ट की सुविधा का इस्तेमाल, कई अलग-अलग कोड एडिटर में किया जा सकता है. साथ ही, यह आपको कोड लिखते समय सलाह दे सकती है और इनलाइन सुझाव दे सकती है. हम अपनी रेसिपी के डेटा को व्यवस्थित करते समय, इस जनरेटिव असिस्टेंट का फ़ायदा लेंगे.

  1. खोज बार का इस्तेमाल करके, Colab Enterprise पर जाएं और नोटबुक बनाएं. अगर आपको Colab की नई सुविधाओं को आज़माने का ऑफ़र मिलता है, तो उसे खारिज कर दें. रनटाइम और नोटबुक की कंप्यूटिंग पावर देखने के लिए, अपने नए नोटबुक के सबसे ऊपर दाएं कोने में मौजूद कनेक्ट करें को दबाएं.

386577c713522b4d.png

  1. Colab Enterprise के फ़ाइलों वाले पैनल में, मौजूदा नोटबुक के नाम के बगल में मौजूद तीन बिंदु वाले मेन्यू का इस्तेमाल करके, उसका नाम बदलें Data Wrangling.

4cb787f255bac415.png

  1. नया + टेक्स्ट बॉक्स बनाएं और उसे ऊपर वाले ऐरो का इस्तेमाल करके, पेज की पहली सेल पर ले जाएं.

6a08b3ccc9c2174b.png

  1. टेक्स्ट बॉक्स में बदलाव करें और यह डालें:
# Data Wrangling

Import the Pandas library
  1. आपने जो टेक्स्ट ब्लॉक बनाया है उसके नीचे मौजूद कोड ब्लॉक में, imp टाइप करें. इसके बाद, Gemini Code Assist आपको बाकी इंपोर्ट के लिए, स्लेटी रंग में सुझाव देगा. सुझाव स्वीकार करने के लिए, Tab दबाएं.
import pandas as pd
  1. इंपोर्ट कोड बॉक्स के नीचे, एक और टेक्स्ट बॉक्स बनाएं और इसमें यह डालें:
Create a Pandas DataFrame from: gs://labs.roitraining.com/labs/recipes/recipe_dataset.csv. View the first few records.
  1. कोई दूसरा कोड ब्लॉक बनाएं और उसमें बदलाव करें. फिर से, df टाइप करना शुरू करें और Gemini Code Assistant से जनरेट किए गए कोड की जांच करें. अगर आपको जनरेट किए गए सुझाव के ऊपर, Python कीवर्ड की ऑटोकंप्लीट ड्रॉपलिस्ट दिखती है, तो सुझाया गया हल्का स्लेटी रंग का कोड देखने के लिए, 'बचें' दबाएं. सुझाव स्वीकार करने के लिए, फिर से Tab दबाएं. अगर आपके सुझाव में head() फ़ंक्शन कॉल शामिल नहीं है, तो उसे जोड़ें.
df = pd.read_csv('gs://labs.roitraining.com/labs/recipes/recipe_dataset.csv')
df.head()
  1. अपनी पहली कोड सेल पर क्लिक करें, जहां आपने Pandas इंपोर्ट किया है. इसके बाद, चुनी गई सेल को चलाने के लिए, कमांड मेन्यू या कीबोर्ड का इस्तेमाल करें. कीबोर्ड पर shift+enter दबाने से, सेल चलने लगेगी और फ़ोकस अगली सेल पर शिफ़्ट हो जाएगा. साथ ही, ज़रूरत पड़ने पर एक नई सेल भी बन जाएगी. आगे बढ़ने से पहले, सेल के लागू होने का इंतज़ार करें.

ध्यान दें: जब किसी सेल को लागू नहीं किया गया होगा, तो आपको बाईं ओर [ ] दिखेगा. सेल के चालू होने के दौरान, आपको घूमता हुआ ऐनिमेशन दिखेगा. सेल भर जाने के बाद, [13] जैसा कोई नंबर दिखेगा. 9. उस सेल को चलाएं जो CSV को DataFrame में लोड करती है. फ़ाइल के लोड होने का इंतज़ार करें और डेटा की पहली पांच पंक्तियों की जांच करें. यह रेसिपी का वह डेटा है जिसे हम BigQuery में लोड करेंगे. साथ ही, इसका इस्तेमाल रेसिपी जनरेटर को बेहतर बनाने के लिए किया जाएगा. 10. नया कोड ब्लॉक बनाएं और नीचे दी गई टिप्पणी डालें. टिप्पणी टाइप करने के बाद, कोड की अगली लाइन पर जाएं. आपको सुझाव df.columns दिखेगा. इसे स्वीकार करें और फिर सेल को चलाएं.

# List the current DataFrame column names

हमने अभी-अभी यह दिखाया है कि Jupyter नोटबुक में Gemini Code Assist की मदद पाने के लिए, आपके पास दो विकल्प हैं: कोड सेल के ऊपर टेक्स्ट सेल या कोड सेल में टिप्पणियां. कोड सेल में की गई टिप्पणियां, Jupyter Notebooks में अच्छी तरह से काम करती हैं. हालांकि, यह तरीका Google के Gemini कोड असिस्ट की सुविधा के साथ काम करने वाले किसी भी दूसरे आईडीई में भी काम करेगा.

  1. आइए, कॉलम में मौजूद ग़ैर-ज़रूरी डेटा को हटाते हैं. कॉलम Unnamed: 0 का नाम बदलकर id और link का नाम बदलकर uri करें. कोड बनाने के लिए, अपनी पसंद के प्रॉम्प्ट > कोड तकनीकों का इस्तेमाल करें. इसके बाद, जब आप संतुष्ट हो जाएं, तो सेल चलाएं.
# Rename the column 'Unnamed: 0' to 'id' and 'link' to 'uri'
df.rename(columns={'Unnamed: 0': 'id', 'link': 'uri'}, inplace=True)
  1. source और NER कॉलम हटाएं और पहली कुछ पंक्तियां देखने के लिए, head() का इस्तेमाल करें. फिर से, Gemini से मदद पाएं. आखिरी दो लाइनों को चलाएं और नतीजों की जांच करें.
# Remove the source and NER columns
df.drop(columns=['source', 'NER'], inplace=True)
df.head()
  1. आइए, देखें कि हमारे डेटासेट में कितने रिकॉर्ड हैं. फिर से, प्रॉम्प्ट करने की अपनी पसंदीदा तकनीक से शुरुआत करें और देखें कि क्या Gemini की मदद से कोड जनरेट किया जा सकता है.
# Count the records in the DataFrame
df.shape # count() will also work
  1. 2.23 लाख रिकॉर्ड, शायद रेसिपी के लिए हमारे पास मौजूद समय से ज़्यादा हैं. आज के एक्सरसाइज़ के लिए, Agent Builder में इंडेक्स करने की प्रोसेस में काफ़ी समय लगेगा. समझौते के तौर पर, 1,50,000 रेसिपी का सैंपल लें और उस पर काम करें. सैंपल लेने के लिए, अपने प्रॉम्प्ट > कोड के तरीके का इस्तेमाल करें और उसे dfs (छोटे के लिए s) नाम की नई डेटाफ़्रेम में सेव करें.
# Sample out 150,000 records into a DataFrame named dfs
dfs = df.sample(n=150000)
  1. हमारा रेसिपी सोर्स डेटा, BigQuery में लोड होने के लिए तैयार है. डेटा लोड करने से पहले, BigQuery पर जाएं और अपनी टेबल को सेव करने के लिए डेटासेट तैयार करें. Google Cloud Console में, BigQuery पर जाने के लिए खोज बॉक्स का इस्तेमाल करें. BigQuery पर राइट क्लिक करके, उसे नए ब्राउज़र टैब में खोला जा सकता है.
  2. अगर यह पहले से नहीं दिख रहा है, तो Cloud Console के सबसे ऊपर दाईं ओर मौजूद Gemini लोगो का इस्तेमाल करके, Gemini एआई चैट पैनल खोलें. अगर आपसे एपीआई को फिर से चालू करने के लिए कहा जाता है, तो 'चालू करें' दबाएं या पेज को रीफ़्रेश करें. प्रॉम्प्ट चलाएं: What is a dataset used for in BigQuery? जवाब देखने के बाद, पूछें: How can I create a dataset named recipe_data using the Cloud Console? नतीजों की तुलना यहां दिए गए कुछ चरणों से करें.

3c38e5975c5c519.png

  1. BigQuery एक्सप्लोरर पैनल में, अपने प्रोजेक्ट आईडी के बगल में मौजूद तीन बिंदु वाले कार्रवाइयां देखें मेन्यू पर क्लिक करें. इसके बाद, डेटासेट बनाएं चुनें.

e28c2fc55a04c694.png

  1. recipe_data का डेटासेट और आईडी दें. जगह का टाइप अमेरिका पर सेट रहने दें और डेटासेट बनाएं. अगर आपको गड़बड़ी का कोई ऐसा मैसेज मिलता है जिसमें लिखा होता है कि डेटासेट पहले से ही मौजूद है, तो बस आगे बढ़ें.

BigQuery में बनाए गए डेटासेट के साथ, अपनी नोटबुक पर वापस स्विच करके डेटा डालें. 19. Colab Enterprise में, डेटा व्रणलिंग नोटबुक पर वापस जाएं. नई कोड सेल में, project_id नाम का वैरिएबल बनाएं और इसका इस्तेमाल अपने मौजूदा प्रोजेक्ट आईडी को सेव करने के लिए करें. इन निर्देशों के ऊपर बाईं ओर, 'लैब बंद करें' बटन के नीचे, आपको मौजूदा प्रोजेक्ट आईडी दिखेगा. अगर आप चाहें, तो यह Cloud Console के होम पेज पर भी उपलब्ध है. अपने project_id वैरिएबल में वैल्यू असाइन करें और सेल चलाएं.

# Create a variable to hold the current project_id
project_id='YOUR_PROJECT_ID'
  1. प्रॉम्प्ट > कोड के तरीके का इस्तेमाल करके, कोड का एक ब्लॉक बनाएं. यह ब्लॉक, हमारे बनाए गए डेटासेट recipe_data में recipes नाम की टेबल में, DataFrame dfs को डाल देगा. सेल चलाएं.
dfs.to_gbq(destination_table='recipe_data.recipes', project_id=project_id, if_exists='replace')

7. चौथा टास्क. रेसिपी जनरेटर के लिए, Vertex AI Agent Builder में खोज ऐप्लिकेशन बनाना

बहुत बढ़िया, रेसिपी के डेटा की बनाई गई टेबल का इस्तेमाल करके, रेसिपी जनरेटर के लिए एक अच्छा डेटा सोर्स बनाएं. हम उसी तरीके का इस्तेमाल करेंगे जो हमने अपने कुकिंग चैटबॉट के लिए किया था. हम डेटा स्टोर बनाने के लिए, Vertex AI Agent Builder का इस्तेमाल करेंगे. इसके बाद, हम उस डेटा स्टोर का इस्तेमाल, Search ऐप्लिकेशन के लिए सोर्स ऑफ़ ट्रूथ के तौर पर करेंगे.

अगर आपको Agent Builder सर्च ऐप्लिकेशन बनाने का तरीका याद नहीं है, तो Google Cloud Console में Gemini से पूछें. इसके अलावा, यहां दिया गया तरीका भी अपनाया जा सकता है.

  1. एजेंट बिल्डर पर जाने के लिए, खोज का इस्तेमाल करें. डेटा स्टोर और डेटा स्टोर बनाएं खोलें. इस बार, BigQuery डेटा स्टोर का टाइप चुनें.
  2. टेबल की चुनी गई सेल में, ब्राउज़ करें दबाएं और recipes खोजें. अपनी टेबल के बगल में मौजूद रेडियो बटन को चुनें. अगर आपको qwiklabs-gcp-... प्रोजेक्ट के अन्य रेसिपी दिखते हैं, तो पक्का करें कि आपने अपने प्रोजेक्ट की रेसिपी चुनी हो.

ध्यान दें: अगर आपने recipes के बगल में मौजूद रेडियो बटन को चुनने के बजाय, recipes पर क्लिक किया, तो आपके ब्राउज़र में एक नया टैब खुलेगा. साथ ही, आपको BigQuery में टेबल की खास जानकारी वाले पेज पर ले जाया जाएगा. बस ब्राउज़र टैब बंद करें और एजेंट बिल्डर में रेडियो बटन चुनें. 3. बाकी डिफ़ॉल्ट विकल्पों की जांच करें, लेकिन उनमें बदलाव न करें. इसके बाद, जारी रखें पर क्लिक करें. 4. स्कीमा की समीक्षा वाले पेज पर, शुरुआती डिफ़ॉल्ट कॉन्फ़िगरेशन की जांच करें, लेकिन कुछ भी न बदलें. जारी रखें 5. डेटास्टोर को recipe-data नाम दें. डेटास्टोर आईडी में बदलाव करें और उसे recipe-data-id पर सेट करें. डेटा स्टोर बनाएं. 6. बाईं ओर मौजूद नेविगेशन मेन्यू का इस्तेमाल करके, ऐप्लिकेशन पर जाएं और ऐप्लिकेशन बनाएं पर क्लिक करें. 7. Search ऐप्लिकेशन को फिर से चुनें. ऐप्लिकेशन का नाम recipe-search रखें और आईडी को recipe-search-id पर सेट करें. कंपनी का नाम Google पर सेट करें और जारी रखें पर क्लिक करें. 8. इस बार, recipe-data डेटा सोर्स देखें. ऐप्लिकेशन बनाएं.

हमारी डेटाबेस टेबल को इंडेक्स होने में कुछ समय लगेगा. इस दौरान, BigQuery के नए डेटा कैनवस के साथ प्रयोग करते हैं और देखते हैं कि क्या हमें एक या दो दिलचस्प रेसिपी मिल सकती हैं. 9. BigQuery पर जाने के लिए, खोज बॉक्स का इस्तेमाल करें. BigQuery Studio में सबसे ऊपर, सबसे दाएं टैब के बगल में मौजूद डाउन ऐरो पर क्लिक करें. इसके बाद, डेटा कैनवस चुनें. क्षेत्र को us-central1 पर सेट करें.

5d562cddb1717c32.png

  1. डेटा कैनवस के खोज बॉक्स में, recipes खोजें और अपनी टेबल को कैनवस में जोड़ें.
  2. आपकी रेसिपी टेबल का विज़ुअल, BigQuery डेटा कैनवस में लोड हो जाएगा. टेबल के स्कीमा को एक्सप्लोर किया जा सकता है, टेबल में मौजूद डेटा की झलक देखी जा सकती है, और अन्य जानकारी की जांच की जा सकती है. टेबल के नीचे, क्वेरी पर क्लिक करें.
  3. कैनवस पर, BigQuery की क्वेरी डायलॉग बॉक्स जैसा एक डायलॉग बॉक्स दिखेगा. हालांकि, इसमें एक और चीज़ जोड़ी गई है: क्वेरी विंडो के ऊपर एक टेक्स्ट बॉक्स है. इसका इस्तेमाल करके, Gemini से मदद मांगी जा सकती है. आइए, देखते हैं कि हमें अपने सैंपल में केक बनाने की कुछ रेसिपी मिल सकती हैं या नहीं. यहां दिया गया प्रॉम्प्ट चलाएं. इसके लिए, टेक्स्ट टाइप करें और एसक्यूएल जनरेशन को ट्रिगर करने के लिए, Enter/Return दबाएं:
Please select the title and ingredients for all the recipes with a title that contains the word cake.
  1. जनरेट की गई एसक्यूएल क्वेरी देखें. जब आप अपनी क्वेरी से संतुष्ट हो जाएं, तो उसे चालू करें.
  2. यह भी बुरा नहीं है! आगे बढ़ने से पहले, कुछ और प्रॉम्प्ट और क्वेरी आज़माएं. एक्सपेरिमेंट करते समय, कम जानकारी वाले प्रॉम्प्ट आज़माएं. इससे आपको यह पता चलेगा कि कौनसे प्रॉम्प्ट काम के हैं और कौनसे नहीं. उदाहरण के लिए, यह प्रॉम्प्ट:
Do I have any chili recipes?

(नई क्वेरी चलाना न भूलें) चिली की रेसिपी की सूची दिखाई गई, लेकिन इसमें तब तक सामग्री नहीं दिखी, जब तक मैंने इसे इस तरह से बदला नहीं:

Do I have any chili recipes?  Please include their title and ingredients.

(हां, मैं निर्देश देते समय कृपया कहती हूं. मेरी मम्मी को बहुत खुशी होगी.)

मुझे पता चला है कि एक चिली रेसिपी में मशरूम शामिल हैं. कौन चाहता है कि चिली में मशरूम हो? मैंने Gemini से उन रेसिपी को हटाने में मदद करने के लिए कहा.

Do I have any chili recipes?  Please include their title and ingredients, and ignore any recipes with mushrooms as an ingredient.

8. पांचवां टास्क. Gemini की मदद से, Python और Streamlit के मुख्य वेब ऐप्लिकेशन को फ़्रेम करना

Vertex AI Agent Builder के दोनों डेटा स्टोर को इंडेक्स किया जा चुका है और हमारे खोज ऐप्लिकेशन लॉन्च होने के लिए तैयार हैं. अब वेब ऐप्लिकेशन बनाने का समय आ गया है.

हम इस काम के दौरान, Gemini Code Assist का इस्तेमाल करेंगे. Visual Studio Code में Gemini Code Assist का इस्तेमाल करने के बारे में ज़्यादा जानने के लिए, दस्तावेज़ यहां देखें

हम Google Cloud Workstation में अपना डेवलपमेंट करेंगे. यह क्लाउड पर आधारित डेवलपमेंट एनवायरमेंट है. हमारे मामले में, इसमें Eclipse Theia (ओपन सोर्स Visual Studio Code) पहले से लोड है. इस एक्सरसाइज़ में, ऑटोमेट की गई स्क्रिप्ट ने हमारे लिए Cloud Workstation क्लस्टर और कॉन्फ़िगरेशन बना दिया है. हालांकि, हमें अब भी Cloud Workstation खुद बनाना होगा. अगर आपको Cloud Workstations और उनके इस्तेमाल के बारे में ज़्यादा जानकारी चाहिए, तो Gemini Cloud Assist से पूछें :-)

  1. खोज बार का इस्तेमाल करके, क्लाउड वर्कस्टेशन पर जाएं. इसके बाद, वर्कस्टेशन बनाएं पर जाएं. वर्कस्टेशन को dev-env नाम दें और my-config कॉन्फ़िगरेशन का इस्तेमाल करें. वर्कस्टेशन बनाएं.
  2. कुछ ही मिनटों में, आपको 'मेरे वर्कस्टेशन' सूची में अपना नया वर्कस्टेशन दिखेगा. dev-env को शुरू करें. इसके चालू होने के बाद, डेवलपमेंट एनवायरमेंट लॉन्च करें.
  3. वर्कस्टेशन एडिटर, नए ब्राउज़र टैब में खुलेगा. कुछ देर बाद, आपको Theia (Visual Studio Code) का जाना-पहचाना इंटरफ़ेस दिखेगा. इंटरफ़ेस की बाईं ओर, सोर्स कंट्रोल टैब को बड़ा करें और क्लोन रिपॉज़िटरी दबाएं.

c03d05b42d28a518.png

  1. डेटा स्टोर करने की जगह के यूआरएल के लिए, https://github.com/haggman/recipe-app डालें. अपने user फ़ोल्डर में रिपॉज़िटरी को क्लोन करें. इसके बाद, बदलाव करने के लिए क्लोन किए गए रिपॉज़िटरी को खोलें.
  2. क्लोन किए गए फ़ोल्डर को एक्सप्लोर करने और अपने वेब ऐप्लिकेशन पर काम शुरू करने से पहले, हमें एडिटर के Cloud Code प्लग इन को Google Cloud में लॉग इन करना होगा. साथ ही, हमें Gemini को चालू करना होगा. चलिए, अब ऐसा करते हैं. एडिटर में सबसे नीचे बाईं ओर, Cloud Code - साइन इन करें पर क्लिक करें. अगर आपको लिंक नहीं दिखता है, तो एक मिनट इंतज़ार करें और फिर से देखें.

f4ebfbd96026c0d8.png

  1. टर्मिनल विंडो में एक लंबा यूआरएल दिखेगा. ब्राउज़र में यूआरएल खोलें और अपने Google Cloud एनवायरमेंट को Cloud Code का ऐक्सेस देने के लिए, बताया गया तरीका अपनाएं. पुष्टि करते समय, अपने निजी Google Cloud खाते के बजाय, गतिविधि के लिए बनाए गए अपने student-... खाते का इस्तेमाल करें. आखिरी डायलॉग में, पुष्टि करने के लिए मिला कोड कॉपी करें और उसे अपने Cloud Workstation ब्राउज़र टैब में, वेटिंग टर्मिनल विंडो में चिपकाएं.
  2. कुछ देर बाद, आपके एडिटर के सबसे नीचे बाईं ओर मौजूद Cloud Code का लिंक, Cloud Code - कोई प्रोजेक्ट नहीं में बदल जाएगा. कोई प्रोजेक्ट चुनने के लिए, नए लिंक पर क्लिक करें. कमांड पैलेट, एडिटर के सबसे ऊपर खुलना चाहिए. Google Cloud प्रोजेक्ट चुनें पर क्लिक करें और अपना qwiklabs-gcp-... प्रोजेक्ट चुनें. कुछ देर बाद, आपके एडिटर के नीचे बाईं ओर मौजूद लिंक अपडेट हो जाएगा और आपका प्रोजेक्ट आईडी दिखेगा. इससे पता चलता है कि Cloud Code, आपके काम करने वाले प्रोजेक्ट से जुड़ गया है.
  3. अपने प्रोजेक्ट से Cloud Code को कनेक्ट करने के बाद, अब Gemini Code Assist को चालू किया जा सकता है. एडिटर इंटरफ़ेस के सबसे नीचे दाईं ओर, क्रॉस किए गए Gemini लोगो पर क्लिक करें. Gemini Chat पैनल, एडिटर की बाईं ओर खुलेगा. Google Cloud प्रोजेक्ट चुनें पर क्लिक करें. कमांड पैलेट खुलने पर, अपना qwiklabs-gcp-... प्रोजेक्ट चुनें. अगर आपने सही तरीके से निर्देशों का पालन किया है और Google ने कुछ भी नहीं बदला है, तो आपको अब Gemini चैट विंडो दिखेगी.

70e4e06ed6565329.png

  1. आखिर में, एडिटर टर्मिनल विंडो को भी इसी तरह कॉन्फ़िगर करें. टर्मिनल विंडो खोलने के लिए, हैमबर्गर मेन्यू > व्यू > टर्मिनल का इस्तेमाल करें. gcloud init को चलाएं. Cloud Shell टर्मिनल को अपने qwiklabs-gcp-... प्रोजेक्ट के साथ काम करने की अनुमति देने के लिए, लिंक का फिर से इस्तेमाल करें. जब आपसे कहा जाए, तो अपने qwiklabs-gcp-... प्रोजेक्ट का अंकों वाला विकल्प चुनें.
  2. बहुत बढ़िया, हमारे टर्मिनल, Gemini चैट, और Cloud Code कॉन्फ़िगरेशन सभी सेट हैं. अब एक्सप्लोरर टैब खोलें और मौजूदा प्रोजेक्ट में मौजूद फ़ाइलों को एक्सप्लोर करने के लिए कुछ मिनट दें.

3b2dc3820ed643e2.png

  1. Explorer में, बदलाव करने के लिए अपनी requirements.txt फ़ाइल खोलें. Gemini चैट पैनल पर स्विच करें और पूछें:
From the dependencies specified in the requirements.txt file, what type of application are we building?
  1. इसलिए, हम Python और Streamlit का इस्तेमाल करके एक इंटरैक्टिव वेब ऐप्लिकेशन बना रहे हैं, जो Vertex AI और डिस्कवरी इंजन के साथ इंटरैक्ट कर रहा है. फ़िलहाल, वेब ऐप्लिकेशन कॉम्पोनेंट पर फ़ोकस करते हैं. Gemini के मुताबिक, Streamlit एक फ़्रेमवर्क है. इसकी मदद से, Python में डेटा-ड्रिवन वेब ऐप्लिकेशन बनाए जा सकते हैं. अब पूछें:
Does the current project's folder structure seem appropriate for a Streamlit app?s

आम तौर पर, Gemini में इस तरह की समस्याएं आती हैं. Gemini, बदलाव करने वाले टूल में फ़िलहाल खुली हुई फ़ाइल को ऐक्सेस कर सकता है. हालांकि, वह पूरा प्रोजेक्ट नहीं देख सकता. यह निर्देश देकर देखें:

Given the below, does the current project's file and folder structure seem appropriate for a Streamlit app?

- build.sh
- Home.py
- requirements.txt
- pages
-- Cooking_Advice.py
-- Recipe_Search.py

क्या बेहतर जवाब पाया जा सकता है?

  1. आइए, Streamlit के बारे में ज़्यादा जानें:
What can you tell me about Streamlit?

अच्छा है, इससे हमें पता चलता है कि Gemini, फ़ायदों और नुकसानों के साथ-साथ, खास जानकारी भी दे रहा है.

  1. अगर आपको इसकी कमियों के बारे में जानना है, तो ये सवाल पूछे जा सकते हैं:
What are the major downsides or shortcomings?

ध्यान दें, हमें "Streamlit की" नहीं बोलनी पड़ी, क्योंकि Gemini Chat में बातचीत की सुविधा होती है. हम चैट सेशन में हैं, इसलिए Gemini को पता है कि हम किस बारे में बात कर रहे हैं. अगर आपको किसी भी समय Gemini में की गई चैट का इतिहास मिटाना है, तो Gemini कोड चैट विंडो में सबसे ऊपर मौजूद, ट्रैशबिन आइकॉन का इस्तेमाल करें.

9. छठा टास्क: वेब ऐप्लिकेशन को Cloud Run पर डिप्लॉय करना

बहुत बढ़िया, हमारे पास ऐप्लिकेशन का मुख्य स्ट्रक्चर है, लेकिन क्या यह काम करेगा? इसके अलावा, हमें इसे Google Cloud में कहां होस्ट करना चाहिए?

  1. Gemini की चैट विंडो में, ये सवाल पूछें:
If I containerize this application, what compute technologies
in Google Cloud would be best for hosting it?
  1. याद रखें, अगर आपने पहले से ही अपने आईडीई में काम नहीं किया था, तो Google Cloud Assist का इस्तेमाल भी किया जा सकता है. Google Cloud Console खोलें. इसके बाद, Gemini Cloud Assist खोलें और पूछें:
If I have a containerized web application, where would be the
best place to run it in Google Cloud?

क्या दोनों सेट में एक जैसी सलाह दी गई थी? क्या आप इनमें से किसी भी सुझाव से सहमत/असहमत हैं? याद रखें, Gemini एक जनरेटिव एआई असिस्टेंट है. किसी इंसान की तरह, यह हमेशा आपकी पसंद के मुताबिक जवाब नहीं देगा. इसके बावजूद, Google Cloud और कोड एडिटर में काम करते समय, सहायक की मदद हमेशा आपके साथ होने से, आपको ज़्यादा बेहतर तरीके से काम करने में मदद मिल सकती है.

  1. स्टेटलेस और कम समय तक चलने वाले कंटेनर वाले वेब ऐप्लिकेशन के लिए, Cloud Run एक बेहतरीन विकल्प है. अपने कोड एडिटर की Gemini चैट विंडो में, यह प्रॉम्प्ट आज़माएं:
What steps would be required to run this application in
Cloud Run?
  1. ऐसा लगता है कि सबसे पहले हमें Dockerfile बनाना होगा. एडिटर का इस्तेमाल करके, अपने प्रोजेक्ट फ़ोल्डर के रूट में Dockerfile नाम की फ़ाइल बनाएं. पक्का करें कि आपने गलती से इसे पेज फ़ोल्डर में न डाल दिया हो. बदलाव करने के लिए फ़ाइल खोलें.
  2. Dockerfile बनाने के लिए, Gemini Chat के साइड पैनल का इस्तेमाल करते हैं. नीचे दिए गए प्रॉम्प्ट का इस्तेमाल करें. जब नतीजे चैट में दिखते हैं, तो सुझाए गए Dockerfile में सुझाया गया कोड डालने के लिए, Dockerfile के ठीक ऊपर मौजूद कॉपी आइकॉन के बगल में मौजूद + का इस्तेमाल करें.
Create a Dockerfile for the application in the current folder.
The dependencies are defined in requirements.txt and I want you
to use the Python 3 slim bookworm base image.

यह ज़रूरी नहीं है कि Gemini एक ही प्रॉम्प्ट के लिए हमेशा एक ही जवाब दे. मैंने पहली बार Gemini से Dockerfile बनाने के लिए कहा, तो मुझे वह फ़ाइल मिली जिसका इस्तेमाल करने का सुझाव मैं आपको देना चाहता/चाहती हूं. मुझे अभी यह सुझाव मिला है:

```docker
# Base image
FROM python:3-bookworm-slim

# Set working directory
WORKDIR /app

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    gcc \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

# Install pip and virtualenv
RUN pip install --upgrade pip virtualenv

# Create virtual environment
RUN python3 -m venv venv

# Activate virtual environment
WORKDIR /app/venv/bin
RUN . activate

# Install Streamlit and libraries from requirements.txt
RUN pip install -r requirements.txt

# Copy application files
COPY . /app

# Expose port 8501 for Streamlit
EXPOSE 8501

# Start Streamlit app
CMD ["streamlit", "run", "main.py"]
That's a heck of a Dockerfile. I'd simplify it a bit. We don't need the apt-get section as anything needed for Python is already in our base image. Also, using a virtual environment in a Python container is a waste of space, so I'd remove that. The expose command isn't strictly necessary, but it's fine. Also, it's trying to start main.py which I don't have.

6. Tweak the Dockerfile so it resembles the following:


FROM python:3.11-slim-bookworm

WORKDIR /app

requirements.txt कॉपी करें . RUN pip install –no-cache-dir –upgrade pip &&
pip install –no-cache-dir -r requirements.txt

कॉपी करें . .

CMD ["streamlit", "run", "Home.py"]

7. We need a place in Google cloud where we can store our container image. Let's get a little help from Gemini. In the Google Cloud Console Gemini Cloud Assist ask:

Google Cloud में Docker इमेज को कहां सेव करना सबसे सही है?

8. If one of the answers you received is the Google Container Registry, then I guess Gemini hasn't gotten word that GCR is deprecated. Again, just like human assistants, you may get out of date or simply wrong answers (hallucinations). Always make sure to consider your choices carefully, even when Gemini is recommending something.

Let's go with Artifact Registry. Ask Gemini Cloud Assist how to create a docker registry in Artifact Registry named cooking-images.

Artifact Registry में Docker रजिस्ट्री बनाने के लिए, gcloud का इस्तेमाल कैसे किया जा सकता है?

9. Now ask Gemini how you could use Cloud Build to build a new image named `recipe-web-app` from the Dockerfile in the current folder.

हमने अभी-अभी जो आर्टफ़ैक्ट रजिस्ट्री रिपॉज़िटरी बनाया है उसमें मौजूद, recipe-web-app नाम की इमेज का इस्तेमाल करके, gcloud का इस्तेमाल करके, recipe-web-app नाम की नई Cloud Run सेवा कैसे बनाई जा सकती है?

10. To save you a little time, I've created a script that will create the Artifact Registry repo (if needed), use Cloud Build to build and push the image to the repo, and finally to deploy the application to Cloud Run. In your code editor use the **Explorer** view to open `build.sh` and explore the file.
11. Gemini can operate via the chat window, but it can also work directly in your code file using comments, like we used in the Data Wrangling notebook, and it also may be invoked using Control+i on Windows or Command+i on Mac. Click somewhere in the build.sh script file, activate Gemini using the appropriate Command+i / Control+i command.

<img src="img/61ac2c9a245a3695.png" alt="61ac2c9a245a3695.png"  width="624.00" />

12. At the prompt enter the below. Examine and **Accept** the change.

कृपया मौजूदा फ़ाइल पर टिप्पणी करें.

How cool is that?! How many times have you had to work with someone elses code, only to have to waste time gaining a base understanding of their commentless work before you can even start making your changes. Gemini to the rescue!

13. Let's build and deploy our application. In the terminal window execute the `build.sh` file.

. build.sh

14. If you watch the build process, first it will build the Artifact Registry docker repo. Then, it uses Cloud Build to create the container image from the Dockerfile in the local folder (since we didn't supply a `cloudbuild.yaml`). Lastly, the docker image will be deployed into a new Cloud Run service. At the end of the script you'll get a Cloud Run test URL to use.

Open the returned link in a new tab of your browser. Take a moment and explore the application's structure and pages. Nice, now we need a hook in our generative AI functionality.


## Task 7: Connect the Cooking Advice page to our cookbook-search Agent Builder app



We have the framework for the web application running, but we need to connect the two work pages to our two Vertex AI Agent Builder search apps. Let's start with Cooking Advice.

1. In the Google Cloud console use search to navigate to **Chat** in Vertex AI.
2. In the right hand settings page pane set the model to **gemini-1.5-flash-002**. Slide the output token limit up to the max so the model can return longer answers if needed. Open the **Safety Filter Settings**. Set Hate speech, Sexually explicit content, and Harassment content to **Block some**. Set Dangerous content to **Block few** and **Save**. We're setting Dangerous Content a bit lower because talking about knives and cutting can be misinterpreted by Gemini as violence.
3. Slide on the toggle to enable **Grounding** then click **Customize**. Set the grounding source to **Vertex AI search** and for the datastore path use the following. Change YOUR_PROJECT_ID to the project ID found up near the End Lab button in these instructions, then **Save** the grounding settings

projects/YOUR_PROJECT_ID/locations/global/collections/default_collection/dataStores/old-cookbooks-id

**Note:** If you get an error then you either didn't change the project ID to your actual project ID, or you may have missed the step where you changed the old-cookbooks Agent Builder Data Store ID. Check your Agent Builder &gt; Data Stores &gt; old-cookbooks for its actual Data store ID.

4. Test a couple of chat messages. Perhaps start with the below. Try a few others if you like.


मैं यह कैसे पता करूं कि टमाटर पका है या नहीं?

5. The model works, now let's experiment with the code. Click **Clear Conversation** so our conversations don't become part of the code then click **Get Code**.

<img src="img/dce8ad7ee006cca1.png" alt="dce8ad7ee006cca1.png"  width="624.00" />

6. At the top of the code window, press Open Notebook so we can experiment and perfect the code in Colab Enterprise before integrating it into our app.
7. Take a few minutes to familiarize yourself with the code. Let's make a couple of changes to adapt it to what we want. Before we start, run the first code cell to connect to the compute and install the AI Platform SDK. After the block runs you will be prompted to restart the session. Go ahead and do that.
8. Move to the code we pulled out of Vertex AI Studio. Change the name of the method *multiturn_generate_content* to `start_chat_session`.
9. Scroll to the `model = GenerativeModel(` method call. The existing code defines the `generation_config` and `safety_settings` but doesn't actually use them. Modify the creation of the `GenerativeModel` so it resembles:

model = GenerativeModel( "gemini-1.5-flash-002", tools=tools, generation_config=generation_config, safety_settings=safety_settings, )

10. Lastly, add a final line to the method, just below `chat = model.start_chat()`, so the function returns the `chat` object. The finished function should look like the below.

**Note:** DO NOT COPY this code into your notebook. It is simply here as a sanity check.

def start_chat_session(): vertexai.init(project="qwiklabs-gcp-02-9a7298ceaaec", location="us-central1") tools = [ Tool.from_retrieval( retrieval=grounding.Retrieval( source=grounding.VertexAISearch(datastore="projects/qwiklabs-gcp-02-9a7298ceaaec/locations/global/collections/default_collection/dataStores/old-cookbooks-id"), ) ), ] model = GenerativeModel( "gemini-1.5-flash-002", tools=tools, generation_config=generation_config, safety_settings=safety_settings, ) chat = model.start_chat() return chat

11. Scroll to the bottom of the code cell and change the final line calling the old function so it calls the new function name and stores the returned object in a variable `chat`. Once you are satisfied with your changes, run the cell.

chat = start_chat_session()

12. Create a new code cell and add the comment `# Use chat to invoke Gemini and print out the response`. Move to the next line and type resp and Gemini should auto complete the block for you. Update the prompt to `How can I tell if a tomato is ripe?`. Run the cell

response = chat.send_message("How can I tell if a tomato is ripe?") print(response)

13. That's the response alright, but the part we really want is that nested text field. Modify the codeblock to print just that section, like:


response = chat.send_message("How can I tell if a tomato is ripe?") print(response.candidates[0].content.parts[0].text)

14. Good, now that we have working chat code, let's integrate it into our web application. Copy all the contents of the code cell that creates the `start_chat_session` function (we won't need the test cell). If you click into the cell you can click the triple dot menu in the upper right corner and copy from there

<img src="img/17bf8d947393d4b.png" alt="17bf8d947393d4b.png"  width="326.00" />

15. Switch to your Cloud Workstation editor and open pages\Cooking_Advice.py for editing.
16. Locate the comment:


अपनी नोटबुक से कॉपी किया गया कोड, इस मैसेज के नीचे जोड़ें

17. Paste your copied code just below the above comment. Nice, now we have the section which drives the chat engine via a grounded call to Gemini. Now let's integrate it into Streamlit.
18. Locate section of commented code directly below the comment:

सेशन वैरिएबल सेट अप करने के लिए, यहां दिया गया कोड इस्तेमाल करें

निर्देश मिलने पर, इस ब्लॉक से टिप्पणी हटाना

19. Uncomment this section of code (Up till the next `Setup done, let's build the page UI` section) and explore it. It creates or retrieves the chat and history session variables.
20. Next, we need to integrate the history and chat functionality into the UI. Scroll in the code until you locate the below comment.

चैट इंटरफ़ेस बनाने के लिए कोड

निर्देश मिलने पर, नीचे दिए गए कोड से कमरेंट हटाएं

21. Uncomment the rest of the code below the comment and take a moment to explore it. If you like, highlight it and get Gemini to explain its functionality.
22. Excellent, now let's build the application and deploy it. When the URL comes back, launch the application and give the Cooking Advisor page a try. Perhaps ask it about ripe tomatoes, or the bot knows a good way to prepare brussels sprouts.

. build.sh

How cool is that! Your own personal AI cooking advisor :-)


## Task 8: (Optional) Connect the Recipe Search page to the recipe-search Agent Builder app



When we connected the Cooking Advice page to its grounded source, we did so using the Gemini API directly. For Recipe Search, let's connect to the Vertex AI Agent Builder search app directly.

1. In your Cloud Workstation editor, open the `pages/Recipe_Search.py` page for editing. Investigate the structure of the page.
2. Towards the top of the file, set your project ID.
3. Examine the `search_sample` function. This code more or less comes directly from the Discovery Engine documentation  [here](https://cloud.google.com/generative-ai-app-builder/docs/preview-search-results#genappbuilder_search-python). You can find a working copy in this notebook  [here](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/search/create_datastore_and_search.ipynb).
4. The only change I made was to return the `response.results` instead of just the results. Without this, the return type is an object designed to page through results, and that's something we don't need for our basic application.
5. Scroll to the very end of the file and uncomment the entire section below `Here are the first 5 recipes I found`.
6. Highlight the whole section you just uncommented and open Gemini Code chat. Ask, `Explain the highlighted code`. If you don't have something selected, Gemini can explain the whole file. If you highlight a section and ask Gemini to explain, or comment, or improve it, Gemini will.

Take a moment and read through the explanation. For what it's worth, using a Colab Enterprise notebook is a great way to explore the Gemini APIs before you integrate them into your application. It's especially helpful at exploring some of the newer APIs which may not be documented as well as they could be.
7. At your editor terminal window, run `build.sh` to deploy the final application. Wait until the new version is deployed before moving to the next step.


## Task 9: (Optional) Explore the final application



Take a few minutes to explore the final application.

1. In the Google Cloud console, use search to navigate to **Cloud Run**, then click into your **recipe-web-app**.
2. Locate the application test URL (towards the top) and open it in a new browser tab.
3. The application home page should appear. Note the basic layout and navigation provided by Streamlit, with the python files from the `pages` folder displayed as navigational choices, and the `Home.py` loaded as the home page. Navigate to the **Cooking Advice** page.
4. After a few moments the chat interface will appear. Again, note the nice core layout provided by Streamlit.
5. Try a few cooking related questions and see how the bot functions. Something like:

क्या आपके पास ब्रोकली बनाने के लिए कोई सलाह है?

चिकन सूप की क्लासिक रेसिपी कैसी रहेगी?

मुझे मेरिंज के बारे में बताओ.

6. Now let's find a recipe or two. Navigate to the Recipe Search page and try a few searches. Something like:

चिली कॉन कार्ने

मिर्च, कॉर्न, चावल

लेमन मरैंग पाई

स्ट्रॉबेरी वाली मिठाई

## Congratulations!



You have created an application leveraging Vertex AI Agent Builder applications. Along the way you've explored Gemini Cloud Assist, Gemini Code Assist, and the natural language to SQL features of BigQuery's Data Canvas. Fantastic job!