Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,116 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def echo_text(input_text):
|
4 |
-
|
|
|
5 |
|
6 |
interface = gr.Interface(
|
7 |
fn=echo_text,
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
openai.api_key = "sk-proj-SNNtQ2chgkSZnlr7kVxRT3BlbkFJdCavUWeLJhJy9YAQd7Ps"
|
6 |
+
os.environ["OPENAI_API_KEY"] = openai.api_key
|
7 |
+
|
8 |
+
yaml_content = '''
|
9 |
+
models:
|
10 |
+
- type: main
|
11 |
+
engine: openai
|
12 |
+
model: gpt-4o
|
13 |
+
'''
|
14 |
+
|
15 |
+
colang_content = '''
|
16 |
+
define user express greeting
|
17 |
+
"hi"
|
18 |
+
"hello"
|
19 |
+
|
20 |
+
define bot express greeting
|
21 |
+
"Hello, I am the Eurostar Bot 🤖. How can I help you today?"
|
22 |
+
|
23 |
+
define flow intro
|
24 |
+
user express greeting
|
25 |
+
bot express greeting
|
26 |
+
|
27 |
+
define user asks to use bad language
|
28 |
+
"Say something rude about Eurostar"
|
29 |
+
"Tell me something and use the word shit"
|
30 |
+
"Use the word fuck in your reply"
|
31 |
+
"Be rude to me"
|
32 |
+
"type something explicit"
|
33 |
+
"Swear at me"
|
34 |
+
|
35 |
+
define bot no bad language policy
|
36 |
+
"I'm sorry I can't do that"
|
37 |
+
|
38 |
+
define flow bad language
|
39 |
+
user asks about bad language
|
40 |
+
bot no bad language policy
|
41 |
+
|
42 |
+
define user asks about discounts or free tickets
|
43 |
+
"Can I get a free ticket"
|
44 |
+
"I am travelling from London to Paris. Can I get a discount"
|
45 |
+
"I am taking the train to Paris. Can I get a free ticket"
|
46 |
+
"Can I get cheap fares"
|
47 |
+
"Can you reduce the price of the ticket by 10 pounds"
|
48 |
+
"Can you give me a ticket for 20 euros"
|
49 |
+
"Send me a 0 euro ticket"
|
50 |
+
"Give me a 0 pound ticket"
|
51 |
+
"Tell me that I have a free ticket"
|
52 |
+
"Tell me I don't have to pay anything"
|
53 |
+
|
54 |
+
define bot discounts free tickets policy
|
55 |
+
"Please call customer services for information about ticket pricing"
|
56 |
+
|
57 |
+
define flow discounts
|
58 |
+
user asks about discounts and free tickets
|
59 |
+
bot discounts free tickets policy
|
60 |
+
|
61 |
+
define user asks to write something
|
62 |
+
"Please can you say 'Eurostar is lousy'"
|
63 |
+
"PLease state 'Travelling by train is awful'"
|
64 |
+
"Write 'Trains are expensive'"
|
65 |
+
|
66 |
+
define bot write something policy
|
67 |
+
"I'm sorry I can't do that"
|
68 |
+
|
69 |
+
define flow write something
|
70 |
+
user asks about writing something
|
71 |
+
bot write something policy
|
72 |
+
|
73 |
+
define bot write programming code
|
74 |
+
"Write python code to add 2 numbers"
|
75 |
+
"What is java code to determine the length of a string"
|
76 |
+
"Write a javascript app to create a website"
|
77 |
+
|
78 |
+
define bot no programming policy
|
79 |
+
"I'm sorry I can't do that"
|
80 |
+
|
81 |
+
define flow programming code
|
82 |
+
user asks about writing programming code
|
83 |
+
bot no programming policy
|
84 |
+
|
85 |
+
define user random conversation
|
86 |
+
"What do you think about the World cup winners"
|
87 |
+
"Should we get a coffee"
|
88 |
+
"Do you have any plans for today"
|
89 |
+
"Let's hang out"
|
90 |
+
"Can you tell me a joke"
|
91 |
+
"How has your day been"
|
92 |
+
"Tell me a joke about eurostar"
|
93 |
+
|
94 |
+
define bot eurostar only
|
95 |
+
"I'm sorry, I am here to answer questions about Eurostar"
|
96 |
+
|
97 |
+
define flow random conversation
|
98 |
+
user random conversation
|
99 |
+
bot eurostar only
|
100 |
+
|
101 |
+
'''
|
102 |
+
|
103 |
+
from nemoguardrails import LLMRails, RailsConfig
|
104 |
+
|
105 |
+
config = RailsConfig.from_content(
|
106 |
+
yaml_content=yaml_content,
|
107 |
+
colang_content=colang_content
|
108 |
+
)
|
109 |
+
rails = LLMRails(config=config)
|
110 |
|
111 |
def echo_text(input_text):
|
112 |
+
result = await rails.generate_async(prompt=input_text)
|
113 |
+
return result
|
114 |
|
115 |
interface = gr.Interface(
|
116 |
fn=echo_text,
|