Spaces:
Sleeping
Sleeping
Commit
·
cf24a30
1
Parent(s):
f324b20
chatbot_using_gradio
Browse filesIt creates chatbot interface using gradio, model used is "gpt-3.5-turbo"
- chatbot.py +24 -0
chatbot.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
messages = [
|
| 4 |
+
{"role": "system", "content": "You are an AI assistant that only gives responses from the website https://i-venture.org/ and you help people make decisions about how to make a difference in others' lives. You also provide the relevant links from that website as part of your answers."},
|
| 5 |
+
]
|
| 6 |
+
|
| 7 |
+
def chatbot(input):
|
| 8 |
+
if input:
|
| 9 |
+
context = create_context(input, df)
|
| 10 |
+
message=f"Answer the question based on the context below, and if the question can't be answered based on the context, say \"I don't know\"\n\nContext: {context}\n\n---\n\nQuestion: {input}\nAnswer:",
|
| 11 |
+
messages.append({"role": "user", "content": message})
|
| 12 |
+
chat = openai.ChatCompletion.create(
|
| 13 |
+
temperature=0.5, model="gpt-3.5-turbo", messages=messages,
|
| 14 |
+
)
|
| 15 |
+
reply = chat.choices[0].message.content
|
| 16 |
+
messages.append({"role": "assistant", "content": reply})
|
| 17 |
+
return reply
|
| 18 |
+
|
| 19 |
+
inputs = gr.inputs.Textbox(lines=7, label="Chat with I-venture @ ISB AI powered bot")
|
| 20 |
+
outputs = gr.outputs.Textbox(label="Reply")
|
| 21 |
+
|
| 22 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Talk with I-venture @ ISB",
|
| 23 |
+
description="Anything you want to find out about entreprenuership at ISB. Sample questions include >>> how to get incubated at ISB Dlabs? >>> What is the team behind I-venture @ ISB? >>> and more",
|
| 24 |
+
theme="compact").launch(share=True, debug=True)
|