code: import streamlit as st
  import requests
  import base64
  import os
  import llama_index
  from audio_recorder_streamlit import audio_recorder
  from openai import OpenAI
  from llama_index import VectorStoreIndex, SimpleDirectoryReader
  from scipy.io.wavfile import write
  os.environ['OPENAI_API_KEY'] = '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'
  API_KEY = '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'
  def RAG(text):
      documents = SimpleDirectoryReader("db3").load_data()
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(text)
      
      # Extract the text from the response
      response_text = response.response if hasattr(response, 'response') else str(response)
  
      return response_text
  def linkRAGhindi(text):
      new_prompt="निम्नलिखित प्रश्न के लिए सबसे उपयुक्त वेबसाइट लिंक दें"+text
      documents = SimpleDirectoryReader("db1").load_data()
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(new_prompt)
      
      # Extract the text from the response
      response_text = response.response if hasattr(response, 'response') else str(response)
  
      return response_text
  def rechindi(text):
      new_prompt="निम्नलिखित प्रश्न के लिए सबसे उपयुक्त वेबसाइट लिंक दें"+text
      documents = SimpleDirectoryReader("db2").load_data()
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(new_prompt)
      
      # Extract the text from the response
      response_text = response.response if hasattr(response, 'response') else str(response)
      return response_text
  def linkRAGenglish(text):
      new_prompt="Give the most appropiate website link for the following question "+text
      documents = SimpleDirectoryReader("db1").load_data()
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(new_prompt)
      # Extract the text from the response
      response_text = response.response if hasattr(response, 'response') else str(response)
      return response_text
  def recenglish(text):
      new_prompt="Give the most intresting other website link for the following question "+text
      documents = SimpleDirectoryReader("db2").load_data()
      index = VectorStoreIndex.from_documents(documents)
      query_engine = index.as_query_engine()
      response = query_engine.query(new_prompt)
      # Extract the text from the response
      response_text = response.response if hasattr(response, 'response') else str(response)
      return response_text
  def transcribe_text_to_voice_english(audio_location):
      client = OpenAI(api_key=API_KEY)
      audio_file = open(audio_location, "rb")
      transcript = client.audio.transcriptions.create(model="whisper-1", file=audio_file)
      return transcript.text
  
  def transcribe_text_to_voice_hindi(audio_location):
      url = "https://api.runpod.ai/v2/faster-whisper/runsync"
      
      with open(audio_location, "rb") as audio_file:
          audio_base64 = base64.b64encode(audio_file.read()).decode('utf-8')
  
      payload = {
          "input": {
              "audio_base64": audio_base64,
              "model": "small",
              "transcription": "plain_text",
              "translate": True,
              "language": "hi",
              "temperature": 0,
              "best_of": 5,
              "beam_size": 5,
              "patience": 1,
              "suppress_tokens": "-1",
              "condition_on_previous_text": False,
              "temperature_increment_on_fallback": 0.2,
              "compression_ratio_threshold": 2.4,
              "logprob_threshold": -1,
              "no_speech_threshold": 0.6,
              "word_timestamps": False
          },
          "enable_vad": False
      }
  
      headers = {
          "accept": "application/json",
          "content-type": "application/json",
          "authorization": "X01PG949AHTOVRYHLQZKSRIWN82UHBUU5JYLNAHM"
      }
  
      response = requests.post(url, json=payload, headers=headers)
      response_json = response.json()
      transcription = response_json["output"]["transcription"]
      translation = response_json["output"]["translation"].strip().split('\n')[-1].strip()
      return transcription, translation
  
  
  def recommendation(text):
      client = OpenAI(api_key=API_KEY)
      messages = [{"role": "user", "content": text}]
      response = client.chat.completions.create(model="gpt-3.5-turbo-1106", messages=messages)
      return response.choices[0].message.content
  def text_to_speech_ai(speech_file_path, api_response):
      client = OpenAI(api_key=API_KEY)
      response = client.audio.speech.create(model="tts-1",voice="nova",input=api_response)
      response.stream_to_file(speech_file_path)
  
  
  
  
  
  st.title("🚀 SHRESHTH 💬 Bhuvan Assistant")
  
  # Radio wheel for language selection
  language = st.radio("Language/भाषा",["English", "हिंदी"])
  # Displaying description based on selected language
  if language == "English":
      mode = st.radio("Select Mode Of Input", ["Voice","Text"])
      st.write("Smart - Helpful - Robust - Effortless - System for Text-to-speech and Human-like Assistance")
      if mode == "Voice" or mode == "आवाज":
          st.write("Click on the voice recorder and let me know how I can help you today with your Queries Regarding Bhuvan!")
          audio_bytes = audio_recorder(
              text="",
              recording_color="#e8b62c",
              neutral_color="#6aa36f",
              icon_name="microphone",
              icon_size="2x",
          )
  
          if audio_bytes:
              # Save the Recorded File
              audio_location = "audio_file.wav"
              with open(audio_location, "wb") as f:
                  f.write(audio_bytes)
      
              if language == "English":
                 text=transcribe_text_to_voice_english(audio_location)
                 st.write(text)
              else:
                 text,trans=transcribe_text_to_voice_hindi(audio_location)
                 st.write(text)
  
  
              link_response = linkRAGenglish(text)
              st.write("SHRESHTH:", link_response)
              api_response = RAG(text)
              st.write("SHRESHTH:", api_response)
              speech_file_path = 'audio_response.mp3'
              text_to_speech_ai(speech_file_path, api_response)
              st.audio(speech_file_path)
              recctext="recommend top three other websites that could interest the user depending on this link and answer : " + link_response + api_response
              recc=linkRAGenglish(recctext)  
              st.write("SHRESHTH:", recc)
      else: 
          # Text input option
          text_input = st.text_area("Enter your text here and press Enter", "")
          if st.button("Submit"):
              # Process the entered text
              link_response = linkRAGenglish(text_input)
              st.write("SHRESHTH:", link_response)
              api_response = RAG(text_input)
              st.write("SHRESHTH:", api_response)
              # Read out the text response using tts
              speech_file_path = 'audio_response.mp3'
              text_to_speech_ai(speech_file_path, api_response)
              st.audio(speech_file_path)
              recctext="recommend top three other websites that could interest the user depending on this link and answer : " + link_response + api_response
              recc=linkRAGenglish(recctext)  
              st.write("SHRESHTH:", recc)
  else:
      mode = st.radio("इनपुट मोड का चयन करें", ["आवाज", "टेक्स्ट"])
      st.write("स्मार्ट - सहायक - मजबूत - प्रयासहीन - पाठ-से-बोल के लिए एक सिस्टम और मानव जैसी सहायता")
  
      if mode == "Voice" or mode == "आवाज" or mode == "ভয়েস":
          st.write("आवाज रेकॉर्डर पर क्लिक करें और मुझसे यह बताएं कि आज आपकी भुवन से संबंधित सवालों में मैं आपकी कैसे मदद कर सकता हूँ!")
          audio_bytes = audio_recorder(
              text="",
              recording_color="#e8b62c",
              neutral_color="#6aa36f",
              icon_name="microphone",
              icon_size="2x",
          )
  
          if audio_bytes:
              # Save the Recorded File
              audio_location = "audio_file.wav"
              with open(audio_location, "wb") as f:
                  f.write(audio_bytes)
  
              if language == "English":
                 text=transcribe_text_to_voice_english(audio_location)
                 st.write(text)
              else:
                 text,trans=transcribe_text_to_voice_hindi(audio_location)
                 st.write(text)
      
              link_response = linkRAGhindi(text)
              st.write("श्रेष्ठ:", link_response)
              api_response = RAG(text)
              st.write("श्रेष्ठ:", api_response)      
              # Read out the text response using tts
              speech_file_path = 'audio_response.mp3'
              text_to_speech_ai(speech_file_path, api_response)
              st.audio(speech_file_path)
              recctext="recommend top three other websites that could interest the user depending on this link and answer : " + link_response + api_response
              recc=rechindi(recctext)  
              st.write("श्रेष्ठ:", recc)
              
      else: 
          # Text input option
          text_input = st.text_area("आप यहाँ अपना टेक्स्ट दर्ज करें और एंटर दबाएं", "")
          if st.button("एंटर"):
              # Process the entered text
              link_response = linkRAGhindi(text_input)
              st.write("श्रेष्ठ:", link_response)
              api_response = RAG(text_input)
              st.write("श्रेष्ठ:", api_response)
      
              # Read out the text response using tts
              speech_file_path = 'audio_response.mp3'
              text_to_speech_ai(speech_file_path, api_response)
              st.audio(speech_file_path)
              recctext="recommend top three other websites that could interest the user depending on this link and answer : " + link_response + api_response
              recc=rechindi(recctext)  
              st.write("श्रेष्ठ:", recc)
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.SimpleDirectoryReader
extract_api: [((4762, 4803), 'streamlit.title', 'st.title', (['"""🚀 SHRESHTH 💬 Bhuvan Assistant"""'], {}), "('🚀 SHRESHTH 💬 Bhuvan Assistant')\n", (4770, 4803), True, 'import streamlit as st\n'), ((4853, 4900), 'streamlit.radio', 'st.radio', (['"""Language/भाषा"""', "['English', 'हिंदी']"], {}), "('Language/भाषा', ['English', 'हिंदी'])\n", (4861, 4900), True, 'import streamlit as st\n'), ((492, 534), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (523, 534), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((950, 992), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (981, 992), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((1410, 1452), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (1441, 1452), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((1886, 1928), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (1917, 1928), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((2359, 2401), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (2390, 2401), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((2714, 2737), 'openai.OpenAI', 'OpenAI', ([], {'api_key': 'API_KEY'}), '(api_key=API_KEY)\n', (2720, 2737), False, 'from openai import OpenAI\n'), ((4000, 4049), 'requests.post', 'requests.post', (['url'], {'json': 'payload', 'headers': 'headers'}), '(url, json=payload, headers=headers)\n', (4013, 4049), False, 'import requests\n'), ((4315, 4338), 'openai.OpenAI', 'OpenAI', ([], {'api_key': 'API_KEY'}), '(api_key=API_KEY)\n', (4321, 4338), False, 'from openai import OpenAI\n'), ((4598, 4621), 'openai.OpenAI', 'OpenAI', ([], {'api_key': 'API_KEY'}), '(api_key=API_KEY)\n', (4604, 4621), False, 'from openai import OpenAI\n'), ((4989, 5040), 'streamlit.radio', 'st.radio', (['"""Select Mode Of Input"""', "['Voice', 'Text']"], {}), "('Select Mode Of Input', ['Voice', 'Text'])\n", (4997, 5040), True, 'import streamlit as st\n'), ((5044, 5157), 'streamlit.write', 'st.write', (['"""Smart - Helpful - Robust - Effortless - System for Text-to-speech and Human-like Assistance"""'], {}), "(\n    'Smart - Helpful - Robust - Effortless - System for Text-to-speech and Human-like Assistance'\n    )\n", (5052, 5157), True, 'import streamlit as st\n'), ((7402, 7456), 'streamlit.radio', 'st.radio', (['"""इनपुट मोड का चयन करें"""', "['आवाज', 'टेक्स्ट']"], {}), "('इनपुट मोड का चयन करें', ['आवाज', 'टेक्स्ट'])\n", (7410, 7456), True, 'import streamlit as st\n'), ((7461, 7568), 'streamlit.write', 'st.write', (['"""स्मार्ट - सहायक - मजबूत - प्रयासहीन - पाठ-से-बोल के लिए एक सिस्टम और मानव जैसी सहायता"""'], {}), "(\n    'स्मार्ट - सहायक - मजबूत - प्रयासहीन - पाठ-से-बोल के लिए एक सिस्टम और मानव जैसी सहायता'\n    )\n", (7469, 7568), True, 'import streamlit as st\n'), ((5198, 5324), 'streamlit.write', 'st.write', (['"""Click on the voice recorder and let me know how I can help you today with your Queries Regarding Bhuvan!"""'], {}), "(\n    'Click on the voice recorder and let me know how I can help you today with your Queries Regarding Bhuvan!'\n    )\n", (5206, 5324), True, 'import streamlit as st\n'), ((5337, 5456), 'audio_recorder_streamlit.audio_recorder', 'audio_recorder', ([], {'text': '""""""', 'recording_color': '"""#e8b62c"""', 'neutral_color': '"""#6aa36f"""', 'icon_name': '"""microphone"""', 'icon_size': '"""2x"""'}), "(text='', recording_color='#e8b62c', neutral_color='#6aa36f',\n    icon_name='microphone', icon_size='2x')\n", (5351, 5456), False, 'from audio_recorder_streamlit import audio_recorder\n'), ((6619, 6675), 'streamlit.text_area', 'st.text_area', (['"""Enter your text here and press Enter"""', '""""""'], {}), "('Enter your text here and press Enter', '')\n", (6631, 6675), True, 'import streamlit as st\n'), ((6687, 6706), 'streamlit.button', 'st.button', (['"""Submit"""'], {}), "('Submit')\n", (6696, 6706), True, 'import streamlit as st\n'), ((7629, 7765), 'streamlit.write', 'st.write', (['"""आवाज रेकॉर्डर पर क्लिक करें और मुझसे यह बताएं कि आज आपकी भुवन से संबंधित सवालों में मैं आपकी कैसे मदद कर सकता हूँ!"""'], {}), "(\n    'आवाज रेकॉर्डर पर क्लिक करें और मुझसे यह बताएं कि आज आपकी भुवन से संबंधित सवालों में मैं आपकी कैसे मदद कर सकता हूँ!'\n    )\n", (7637, 7765), True, 'import streamlit as st\n'), ((7778, 7897), 'audio_recorder_streamlit.audio_recorder', 'audio_recorder', ([], {'text': '""""""', 'recording_color': '"""#e8b62c"""', 'neutral_color': '"""#6aa36f"""', 'icon_name': '"""microphone"""', 'icon_size': '"""2x"""'}), "(text='', recording_color='#e8b62c', neutral_color='#6aa36f',\n    icon_name='microphone', icon_size='2x')\n", (7792, 7897), False, 'from audio_recorder_streamlit import audio_recorder\n'), ((9118, 9182), 'streamlit.text_area', 'st.text_area', (['"""आप यहाँ अपना टेक्स्ट दर्ज करें और एंटर दबाएं"""', '""""""'], {}), "('आप यहाँ अपना टेक्स्ट दर्ज करें और एंटर दबाएं', '')\n", (9130, 9182), True, 'import streamlit as st\n'), ((9194, 9211), 'streamlit.button', 'st.button', (['"""एंटर"""'], {}), "('एंटर')\n", (9203, 9211), True, 'import streamlit as st\n'), ((439, 467), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""db3"""'], {}), "('db3')\n", (460, 467), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((897, 925), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""db1"""'], {}), "('db1')\n", (918, 925), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((1357, 1385), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""db2"""'], {}), "('db2')\n", (1378, 1385), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((1833, 1861), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""db1"""'], {}), "('db1')\n", (1854, 1861), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((2306, 2334), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""db2"""'], {}), "('db2')\n", (2327, 2334), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader\n'), ((6045, 6081), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'link_response'], {}), "('SHRESHTH:', link_response)\n", (6053, 6081), True, 'import streamlit as st\n'), ((6131, 6166), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'api_response'], {}), "('SHRESHTH:', api_response)\n", (6139, 6166), True, 'import streamlit as st\n'), ((6293, 6319), 'streamlit.audio', 'st.audio', (['speech_file_path'], {}), '(speech_file_path)\n', (6301, 6319), True, 'import streamlit as st\n'), ((6531, 6558), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'recc'], {}), "('SHRESHTH:', recc)\n", (6539, 6558), True, 'import streamlit as st\n'), ((6814, 6850), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'link_response'], {}), "('SHRESHTH:', link_response)\n", (6822, 6850), True, 'import streamlit as st\n'), ((6906, 6941), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'api_response'], {}), "('SHRESHTH:', api_response)\n", (6914, 6941), True, 'import streamlit as st\n'), ((7119, 7145), 'streamlit.audio', 'st.audio', (['speech_file_path'], {}), '(speech_file_path)\n', (7127, 7145), True, 'import streamlit as st\n'), ((7357, 7384), 'streamlit.write', 'st.write', (['"""SHRESHTH:"""', 'recc'], {}), "('SHRESHTH:', recc)\n", (7365, 7384), True, 'import streamlit as st\n'), ((8483, 8518), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'link_response'], {}), "('श्रेष्ठ:', link_response)\n", (8491, 8518), True, 'import streamlit as st\n'), ((8568, 8602), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'api_response'], {}), "('श्रेष्ठ:', api_response)\n", (8576, 8602), True, 'import streamlit as st\n'), ((8786, 8812), 'streamlit.audio', 'st.audio', (['speech_file_path'], {}), '(speech_file_path)\n', (8794, 8812), True, 'import streamlit as st\n'), ((9018, 9044), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'recc'], {}), "('श्रेष्ठ:', recc)\n", (9026, 9044), True, 'import streamlit as st\n'), ((9317, 9352), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'link_response'], {}), "('श्रेष्ठ:', link_response)\n", (9325, 9352), True, 'import streamlit as st\n'), ((9408, 9442), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'api_response'], {}), "('श्रेष्ठ:', api_response)\n", (9416, 9442), True, 'import streamlit as st\n'), ((9625, 9651), 'streamlit.audio', 'st.audio', (['speech_file_path'], {}), '(speech_file_path)\n', (9633, 9651), True, 'import streamlit as st\n'), ((9857, 9883), 'streamlit.write', 'st.write', (['"""श्रेष्ठ:"""', 'recc'], {}), "('श्रेष्ठ:', recc)\n", (9865, 9883), True, 'import streamlit as st\n'), ((5846, 5860), 'streamlit.write', 'st.write', (['text'], {}), '(text)\n', (5854, 5860), True, 'import streamlit as st\n'), ((5967, 5981), 'streamlit.write', 'st.write', (['text'], {}), '(text)\n', (5975, 5981), True, 'import streamlit as st\n'), ((8283, 8297), 'streamlit.write', 'st.write', (['text'], {}), '(text)\n', (8291, 8297), True, 'import streamlit as st\n'), ((8404, 8418), 'streamlit.write', 'st.write', (['text'], {}), '(text)\n', (8412, 8418), True, 'import streamlit as st\n')]