Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# Set your password
|
| 5 |
-
my_password = "patti-ai-kb"
|
| 6 |
-
|
| 7 |
# Initialize OpenAI API key
|
| 8 |
openai.api_key = "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"
|
| 9 |
|
|
@@ -22,19 +19,12 @@ def generate_text(prompt):
|
|
| 22 |
return response.choices[0].text.strip()
|
| 23 |
|
| 24 |
# Create Gradio interface
|
| 25 |
-
|
| 26 |
-
input_text = gr.Textbox(label="Enter prompt")
|
| 27 |
-
output_text = gr.Textbox(label="AI response")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return "Invalid password. Please try again."
|
| 32 |
-
response = generate_text(prompt)
|
| 33 |
-
return response
|
| 34 |
-
|
| 35 |
-
demo = gr.Interface(
|
| 36 |
-
fn=generate_with_password,
|
| 37 |
-
inputs=[input_text, password_text],
|
| 38 |
outputs=output_text,
|
| 39 |
title="AI Chatbot for PlanetTogether Knowledge Base",
|
| 40 |
description="Ask a question about the PlanetTogether APS:",
|
|
@@ -43,5 +33,20 @@ demo = gr.Interface(
|
|
| 43 |
theme="default"
|
| 44 |
)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Launch demo
|
| 47 |
-
demo.launch()
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
# Initialize OpenAI API key
|
| 5 |
openai.api_key = "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"
|
| 6 |
|
|
|
|
| 19 |
return response.choices[0].text.strip()
|
| 20 |
|
| 21 |
# Create Gradio interface
|
| 22 |
+
password = "mypassword"
|
| 23 |
+
input_text = gr.inputs.Textbox(label="Enter prompt", placeholder="Enter your question here")
|
| 24 |
+
output_text = gr.outputs.Textbox(label="AI response", placeholder="Waiting for input...")
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=generate_text,
|
| 27 |
+
inputs=input_text,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
outputs=output_text,
|
| 29 |
title="AI Chatbot for PlanetTogether Knowledge Base",
|
| 30 |
description="Ask a question about the PlanetTogether APS:",
|
|
|
|
| 33 |
theme="default"
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# Add password field to header
|
| 37 |
+
demo.add_header("Enter Password", type="password")
|
| 38 |
+
|
| 39 |
+
# Function to check password and show/hide inputs/output
|
| 40 |
+
def check_password(password_input):
|
| 41 |
+
if password_input == password:
|
| 42 |
+
demo.show_input()
|
| 43 |
+
demo.show_output()
|
| 44 |
+
else:
|
| 45 |
+
demo.hide_input()
|
| 46 |
+
demo.hide_output()
|
| 47 |
+
|
| 48 |
+
# Set the callback function for password field
|
| 49 |
+
demo.set_config(callback=check_password)
|
| 50 |
+
|
| 51 |
# Launch demo
|
| 52 |
+
demo.launch(share=True)
|