Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Initialize OpenAI API key
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
# Load text from file
|
| 8 |
+
with open("Dropsheets.txt", "r") as f:
|
| 9 |
+
text = f.read()
|
| 10 |
+
|
| 11 |
+
# Define OpenAI GPT-3.5 model function
|
| 12 |
+
def generate_text(prompt):
|
| 13 |
+
response = openai.Completion.create(
|
| 14 |
+
engine="text-davinci-002",
|
| 15 |
+
temperature=0
|
| 16 |
+
)
|
| 17 |
+
return response.choices[0].text.strip()
|
| 18 |
+
|
| 19 |
+
# Create Gradio interface
|
| 20 |
+
input_text = gr.Textbox(label="Enter prompt")
|
| 21 |
+
output_text = gr.Textbox(label="AI Response")
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=generate_text,
|
| 24 |
+
inputs=input_text,
|
| 25 |
+
outputs=output_text,
|
| 26 |
+
title="AI Chatbot for PlanetTogether Knowledge Base",
|
| 27 |
+
description="Ask a question about the PlanetTogether APS",
|
| 28 |
+
examples=[["How do you create an Alternate Path?"]],
|
| 29 |
+
theme="default"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch demo
|
| 33 |
+
demo.launch(share=True)
|