HealthBOT / app.py
typesdigital's picture
Update app.py
9727a5d
import gradio as gr
import openai
# Set up the OpenAI API credentials
openai.api_key = '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'
# Define a function that takes a user's input as a prompt and uses the OpenAI API to generate a response
def generate_response(prompt):
# Set up the OpenAI API parameters
model_engine = "text-davinci-002"
temperature = 0.7
max_tokens = 100
# Generate the response using the OpenAI API
response = openai.Completion.create(
engine=model_engine,
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens
)
# Extract the generated text from the API response
generated_text = response.choices[0].text.strip()
return generated_text
# Define a Gradio interface for the medical bot
def medical_bot(prompt):
# Generate a response using the OpenAI API
response = generate_response(prompt)
# Return the response to the user
return response
# Set up the Gradio interface for the medical bot
interface = gr.Interface(
fn=medical_bot,
inputs=gr.inputs.Textbox(label="Ask for a health tip or benefit:"),
outputs="text",
title="Medical Bot",
description="Get health tips and benefits from the OpenAI API."
)
# Run the Gradio interface
interface.launch()