Forum Discussion

David_FGL's avatar
David_FGL
New Member
1 year ago
Solved

Erro em script em python no Power Bi Online

Estou programando um script em Python para criar um visual no Power BI. Nesse script, estou utilizando uma API da IA Gemini, e usando minha uma chave de acesso. O código está funcionando no Power Bi desktop.

O problema é que, quando publico o relatório no Workspace, ocorre um erro no visual Python. Ou seja, o visual retorna um erro no visual publicado. Perceba que a chave de acesso à API Gemini está salva localmente no script.

 

O erro é: erro no tempo de execução do script.

 

Segue o Script:


# dataset = pandas.DataFrame(undefined, undefined.1)
# dataset = dataset.drop_duplicates()


import google.generativeai as genai
import os
import matplotlib.pyplot as plt


# Configura a chave API no cliente Generative AI
#genai.configure(api_key=api_key) #solução local
genai.configure(api_key='Minha_chave')




model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Explain how AI works")

import google.generativeai as genai


model = genai.GenerativeModel("gemini-1.5-flash")
chat = model.start_chat(
    history=[
        {"role": "user", "parts": "Hello"},
        {"role": "model", "parts": "Great to meet you. What would you like to know?"},
    ]
)

#pergunta 1

# Encontrar o setor com a menor soma e armazenar em uma variável
setor_menor_nota = dataset.loc[dataset['Soma Nota'].idxmin(), 'setor']
#Salvar o valor da menor Nota
menor_nota = dataset.loc[dataset['setor'] == setor_menor_nota, 'Soma Nota'].values[0]


response1 = chat.send_message(f"Quais ações para um plano de ação a curto prazo e a longo prazo  para um setor com geral de indicadores Lean Manufaturing igual a {menor_nota}, de '{setor_menor_nota}'?(Use No máximo 100 palavras e com no máximo 6 palavras por linha)")



plt.text(0.5, 0.5, response1.text, ha='center', va='center', fontsize=20)
plt.axis('off')  # Remove os eixos
plt.show()
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi David_FGL,
    Thanks for reaching out to the Microsoft fabric community forum.

     

    It looks like the problem which you are facing is coming maybe because of python visuals in PowerBi service runs on a cloud environment and not on your local system which has all the required libraries and APIs in the local environment. There may be some restrictions on the cloud environment that causes the issue with your scripts.
    If this is the case then you can try to use PowerBi parameters to store your API key as its a security risk and won't work in the PowerBi service. Make sure that the workspace you are using might have the required permissions or settings enabled for Python visuals. Also as mentioned earlier by lbendlin, ensure that the libraries and dependencies which you are using are supported by PowerBi Service.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Hammad.
    Community Support Team

     

    If this post helps then please mark it as a solution, so that other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. 

    Thank you.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi David_FGL,
    Thanks for reaching out to the Microsoft fabric community forum.

     

    It looks like the problem which you are facing is coming maybe because of python visuals in PowerBi service runs on a cloud environment and not on your local system which has all the required libraries and APIs in the local environment. There may be some restrictions on the cloud environment that causes the issue with your scripts.
    If this is the case then you can try to use PowerBi parameters to store your API key as its a security risk and won't work in the PowerBi service. Make sure that the workspace you are using might have the required permissions or settings enabled for Python visuals. Also as mentioned earlier by lbendlin, ensure that the libraries and dependencies which you are using are supported by PowerBi Service.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Hammad.
    Community Support Team

     

    If this post helps then please mark it as a solution, so that other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. 

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi David_FGL,

    As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help?

    If yes, you are welcome to share your workaround and mark it as a solution so that other users can benefit as well. If you find a reply particularly helpful to you, you can also mark it as a solution.


    If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.

    Thank you for your patience and look forward to hearing from you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi David_FGL,

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi David_FGL,

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

     

    Thank you.