Spaces:
Runtime error
Runtime error
import openai | |
import gradio as gr | |
# Initialize OpenAI API key | |
openai.api_key = "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" | |
# Load text from file | |
with open("Dropsheets.txt", "r") as f: | |
text = f.read() | |
# Define OpenAI GPT-3.5 model function | |
def generate_text(prompt): | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
temperature=0, | |
max_tokens=1024, | |
prompt=prompt | |
) | |
return response.choices[0].text.strip() | |
# Define password-protected Gradio interface | |
def check_password(password): | |
if password == "patti-ai": | |
gr.Interface.visible = True | |
password_box.visible = False | |
return "Access granted" | |
else: | |
gr.Interface.visible = False | |
password_box.visible = True | |
return "Access denied" | |
# Create Gradio interface | |
password_box = gr.Textbox(label="Enter password", type="password") | |
input_text = gr.Textbox(label="Enter prompt", type="text") | |
output_text = gr.Textbox(label="AI response", type="text") | |
demo = gr.Interface( | |
fn=check_password, | |
inputs=input_text, | |
outputs=output_text, | |
title="AI Chatbot for PlanetTogether Knowledge Base", | |
description="Ask a question about the PlanetTogether APS:", | |
examples=[["How do you create an Alternate Path?"]], | |
theme="default" | |
) | |
# Launch demo | |
demo.launch() | |