Spaces:
Running
Running
bonosa
commited on
Commit
·
15a866b
1
Parent(s):
5856834
basic
Browse files- app.py +25 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
openai.api_key = os.environ['key1']
|
5 |
+
|
6 |
+
def answer_query(prompt):
|
7 |
+
response = openai.Completion.create(
|
8 |
+
engine="text-davinci-003",
|
9 |
+
prompt=prompt,
|
10 |
+
max_tokens=150
|
11 |
+
)
|
12 |
+
message = response.choices[0].text.strip()
|
13 |
+
|
14 |
+
# Check if query is parrot-related
|
15 |
+
if 'parrot' not in prompt.lower():
|
16 |
+
return "This service is only for parrot-related queries."
|
17 |
+
|
18 |
+
# Disclaimer for vet info
|
19 |
+
if 'vet' in prompt.lower() or 'veterinarian' in prompt.lower() or 'medical' in prompt.lower():
|
20 |
+
return f"{message}\n\nPlease note that while I strive to provide accurate information, I'm an AI and not a veterinarian. Always consult with a professional for medical advice."
|
21 |
+
|
22 |
+
return message
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=answer_query, inputs="text", outputs="text")
|
25 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
gradio
|