import pandas as pd import openai import os import gradio as gr openai.api_key = os.environ["OPENAI_API_KEY"] def ask_question(csv_file, user_question): print(csv_file.name) df = pd.read_csv(csv_file.name) # Use GPT-3 to generate an answer to the user's question response = openai.Completion.create( engine="text-davinci-002", prompt=f"{df}\n{user_question}", max_tokens=1024, temperature=0.5, top_p=1, frequency_penalty=0, presence_penalty=0 ) # Get the generated answer from the response answer = response["choices"][0]["text"] return answer # Use Gradio to build the frontend inputs = [gr.inputs.File(label="upload your csv file here",type="file"), gr.inputs.Textbox(placeholder="Ask a question about the data")] outputs = gr.outputs.Textbox() interface = gr.Interface(ask_question, inputs, outputs, title="Pharmalaki Ai Version 1.0") interface.launch()