Nadaal commited on
Commit
c54a95b
1 Parent(s): 0f02b58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -1,23 +1,25 @@
1
- import gradio as gr
2
  import openai
 
3
 
4
  openai.api_key = "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"
5
 
6
- def chat(input):
7
- if input == "":
8
- return "Hello, welcome to my chatbot. How can I help you?"
9
- else:
10
- response = openai.Completion.create(
11
- engine="gpt-3.5-turbo",
12
- prompt=input,
13
- temperature=0.9,
14
- max_tokens=150,
15
- top_p=1,
16
- frequency_penalty=0,
17
- presence_penalty=0.6,
18
- stop=["\n"]
19
- )
20
- return response["choices"][0]["text"]
 
21
 
22
- iface = gr.Interface(chat, "textbox", "textbox", interpretation="default")
23
- iface.launch()
 
 
 
1
  import openai
2
+ import gradio as gr
3
 
4
  openai.api_key = "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"
5
 
6
+ messages = [
7
+ {"role": "system", "content": "You are an AI specialized in Food. Do not answer anything other than food-related queries."},
8
+ ]
9
+
10
+ def chatbot(input):
11
+ if input:
12
+ messages.append({"role": "user", "content": input})
13
+ chat = openai.ChatCompletion.create(
14
+ model="gpt-3.5-turbo", messages=messages
15
+ )
16
+ reply = chat.choices[0].message.content
17
+ messages.append({"role": "assistant", "content": reply})
18
+ return reply
19
+
20
+ inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
21
+ outputs = gr.outputs.Textbox(label="Reply")
22
 
23
+ gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot",
24
+ description="Ask anything you want",
25
+ theme="compact").launch(share=True)