Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- .env +1 -0
- .env.example +1 -0
- .github/workflows/update_space.yml +28 -0
- .gitignore +1 -0
- README.md +2 -8
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/backend.cpython-311.pyc +0 -0
- __pycache__/chatbot.cpython-311.pyc +0 -0
- __pycache__/work-app.cpython-311.pyc +0 -0
- app.py +28 -0
- backend.py +56 -0
- chatbot.py +90 -0
- notebook.ipynb +397 -0
- requirements.txt +3 -0
- simple-app.py +18 -0
- test.py +32 -0
- work-app.py +46 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
API_KEY='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'
|
.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
API_KEY=
|
.github/workflows/update_space.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Run Python script
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
build:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout
|
| 14 |
+
uses: actions/checkout@v2
|
| 15 |
+
|
| 16 |
+
- name: Set up Python
|
| 17 |
+
uses: actions/setup-python@v2
|
| 18 |
+
with:
|
| 19 |
+
python-version: '3.9'
|
| 20 |
+
|
| 21 |
+
- name: Install Gradio
|
| 22 |
+
run: python -m pip install gradio
|
| 23 |
+
|
| 24 |
+
- name: Log in to Hugging Face
|
| 25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
| 26 |
+
|
| 27 |
+
- name: Deploy to Spaces
|
| 28 |
+
run: gradio deploy
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: green
|
| 5 |
-
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.35.2
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: chat-bot-test
|
| 3 |
+
app_file: work-app.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 3.35.2
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (3.06 kB). View file
|
|
|
__pycache__/backend.cpython-311.pyc
ADDED
|
Binary file (2.27 kB). View file
|
|
|
__pycache__/chatbot.cpython-311.pyc
ADDED
|
Binary file (2.1 kB). View file
|
|
|
__pycache__/work-app.cpython-311.pyc
ADDED
|
Binary file (2.54 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
with gr.Blocks() as demo:
|
| 6 |
+
chatbot = gr.Chatbot()
|
| 7 |
+
msg = gr.Textbox()
|
| 8 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 9 |
+
|
| 10 |
+
def user(user_message, history):
|
| 11 |
+
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
| 12 |
+
|
| 13 |
+
def bot(history):
|
| 14 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 15 |
+
print(f"{'*'*1000} {history}")
|
| 16 |
+
history[-1][1] = ""
|
| 17 |
+
for character in bot_message:
|
| 18 |
+
history[-1][1] += character
|
| 19 |
+
time.sleep(0.05)
|
| 20 |
+
yield history
|
| 21 |
+
|
| 22 |
+
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 23 |
+
bot, chatbot, chatbot
|
| 24 |
+
)
|
| 25 |
+
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
| 26 |
+
|
| 27 |
+
demo.queue()
|
| 28 |
+
demo.launch()
|
backend.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from typing import List, Dict
|
| 4 |
+
import click
|
| 5 |
+
|
| 6 |
+
# load .env
|
| 7 |
+
import os
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
from pprint import pprint
|
| 10 |
+
|
| 11 |
+
import openai
|
| 12 |
+
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
openai.api_key = os.getenv("API_KEY")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
message_history = []
|
| 20 |
+
cost = 0
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def add_text(user_input: str, history: List, system_role: str = "You are a great assistant"):
|
| 24 |
+
global message_history
|
| 25 |
+
message_history += [{"role": "system", "content": f"{system_role}"}]
|
| 26 |
+
message_history += [{"role": "user", "content": user_input}]
|
| 27 |
+
return gr.update(value="", interactive=False), history + [[user_input, ""]]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def generate_response(history: List, model="gpt-3.5-turbo"):
|
| 31 |
+
global message_history, cost
|
| 32 |
+
|
| 33 |
+
completion = openai.ChatCompletion.create(
|
| 34 |
+
model=model,
|
| 35 |
+
messages=message_history,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
reply_content = completion["choices"][0]["message"]["content"]
|
| 39 |
+
cost += completion.usage.total_tokens * (0.002 / 1_000)
|
| 40 |
+
|
| 41 |
+
message_history += [{"role": "assistant", "content": reply_content}]
|
| 42 |
+
|
| 43 |
+
for char in reply_content:
|
| 44 |
+
history[-1][1] += char
|
| 45 |
+
yield history
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def calc_cost():
|
| 49 |
+
global cost
|
| 50 |
+
return round(cost, 4)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
add_text()
|
| 55 |
+
generate_response()
|
| 56 |
+
calc_cost()
|
chatbot.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
import openai
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
openai.api_key = os.getenv("API_KEY")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def chat(
|
| 14 |
+
user_input: str,
|
| 15 |
+
message_history=[],
|
| 16 |
+
role="user",
|
| 17 |
+
model="gpt-3.5-turbo",
|
| 18 |
+
):
|
| 19 |
+
message_history.append(
|
| 20 |
+
{"role": "system", "content": "You are a helpful assistant."}
|
| 21 |
+
)
|
| 22 |
+
message_history.append({"role": role, "content": f"{user_input}"})
|
| 23 |
+
|
| 24 |
+
completion = openai.ChatCompletion.create(
|
| 25 |
+
model=model,
|
| 26 |
+
messages=message_history,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
reply_content = completion.choices[0].message.content
|
| 30 |
+
message_history.append({"role": "assistant", "content": f"{reply_content}"})
|
| 31 |
+
|
| 32 |
+
# conversation_display = "\n\n".join(
|
| 33 |
+
# [
|
| 34 |
+
# f"{message['role']}: {message['content']}"
|
| 35 |
+
# for message in message_history
|
| 36 |
+
# if message["role"] != "system"
|
| 37 |
+
# ]
|
| 38 |
+
# )
|
| 39 |
+
# return reply_content, conversation_display
|
| 40 |
+
|
| 41 |
+
response = [
|
| 42 |
+
(message_history[i]["content"], message_history[i + 1]["content"])
|
| 43 |
+
for i in range(2, len(message_history) - 1, 2)
|
| 44 |
+
] # convert to tuples of list
|
| 45 |
+
return response
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Create the Gradio interface
|
| 49 |
+
# iface = gr.Interface(
|
| 50 |
+
# fn=chat,
|
| 51 |
+
# inputs=gr.Textbox(placeholder="Enter your message..."),
|
| 52 |
+
# outputs=[
|
| 53 |
+
# gr.Textbox(label="Assistant Reply"),
|
| 54 |
+
# gr.Textbox(label="Conversation History"),
|
| 55 |
+
# ],
|
| 56 |
+
# )
|
| 57 |
+
|
| 58 |
+
# creates a new Blocks app and assigns it to the variable demo.
|
| 59 |
+
with gr.Blocks() as demo:
|
| 60 |
+
# creates a new Chatbot instance and assigns it to the variable chatbot.
|
| 61 |
+
chatbot = gr.Chatbot()
|
| 62 |
+
|
| 63 |
+
# creates a new Row component, which is a container for other components.
|
| 64 |
+
with gr.Row():
|
| 65 |
+
"""creates a new Textbox component, which is used to collect user input.
|
| 66 |
+
The show_label parameter is set to False to hide the label,
|
| 67 |
+
and the placeholder parameter is set"""
|
| 68 |
+
txt = gr.Textbox(
|
| 69 |
+
show_label=False, placeholder="Enter text and press enter"
|
| 70 |
+
).style(container=False)
|
| 71 |
+
"""
|
| 72 |
+
sets the submit action of the Textbox to the predict function,
|
| 73 |
+
which takes the input from the Textbox, the chatbot instance,
|
| 74 |
+
and the state instance as arguments.
|
| 75 |
+
This function processes the input and generates a response from the chatbot,
|
| 76 |
+
which is displayed in the output area."""
|
| 77 |
+
txt.submit(chat, txt, chatbot) # submit(function, input, output)
|
| 78 |
+
# txt.submit(lambda :"", None, txt) #Sets submit action to lambda function that returns empty string
|
| 79 |
+
|
| 80 |
+
"""
|
| 81 |
+
sets the submit action of the Textbox to a JavaScript function that returns an empty string.
|
| 82 |
+
This line is equivalent to the commented out line above, but uses a different implementation.
|
| 83 |
+
The _js parameter is used to pass a JavaScript function to the submit method."""
|
| 84 |
+
txt.submit(
|
| 85 |
+
None, None, txt, _js="() => {''}"
|
| 86 |
+
) # No function, no input to that function, submit action to textbox is a js function that returns empty string, so it clears immediately.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
demo.launch()
|
notebook.ipynb
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 4,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import gradio as gr\n"
|
| 10 |
+
]
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"cell_type": "code",
|
| 14 |
+
"execution_count": 4,
|
| 15 |
+
"metadata": {},
|
| 16 |
+
"outputs": [
|
| 17 |
+
{
|
| 18 |
+
"data": {
|
| 19 |
+
"text/plain": [
|
| 20 |
+
"True"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
"execution_count": 4,
|
| 24 |
+
"metadata": {},
|
| 25 |
+
"output_type": "execute_result"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"source": [
|
| 29 |
+
"import os\n",
|
| 30 |
+
"from dotenv import load_dotenv\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"import openai\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"load_dotenv()"
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "code",
|
| 39 |
+
"execution_count": 5,
|
| 40 |
+
"metadata": {},
|
| 41 |
+
"outputs": [],
|
| 42 |
+
"source": [
|
| 43 |
+
"openai.api_key = os.getenv('API_KEY')"
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"cell_type": "code",
|
| 48 |
+
"execution_count": 6,
|
| 49 |
+
"metadata": {},
|
| 50 |
+
"outputs": [],
|
| 51 |
+
"source": [
|
| 52 |
+
"completion = openai.ChatCompletion.create(\n",
|
| 53 |
+
" model=\"gpt-3.5-turbo\",\n",
|
| 54 |
+
" messages=[{\"role\": \"user\", \"content\": \"Is Nigeria a great country?\"}],\n",
|
| 55 |
+
")\n"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": 7,
|
| 61 |
+
"metadata": {},
|
| 62 |
+
"outputs": [
|
| 63 |
+
{
|
| 64 |
+
"name": "stdout",
|
| 65 |
+
"output_type": "stream",
|
| 66 |
+
"text": [
|
| 67 |
+
"<OpenAIObject chat.completion id=chatcmpl-7TzbaXbPEpF3WRiRpj37LmLyGkvur at 0x7f18dbf1a510> JSON: {\n",
|
| 68 |
+
" \"id\": \"chatcmpl-7TzbaXbPEpF3WRiRpj37LmLyGkvur\",\n",
|
| 69 |
+
" \"object\": \"chat.completion\",\n",
|
| 70 |
+
" \"created\": 1687382678,\n",
|
| 71 |
+
" \"model\": \"gpt-3.5-turbo-0301\",\n",
|
| 72 |
+
" \"choices\": [\n",
|
| 73 |
+
" {\n",
|
| 74 |
+
" \"index\": 0,\n",
|
| 75 |
+
" \"message\": {\n",
|
| 76 |
+
" \"role\": \"assistant\",\n",
|
| 77 |
+
" \"content\": \"As an AI language model, I do not have personal opinions. However, Nigeria has many great qualities such as rich cultural heritage, abundant natural resources, and diverse economy. However, like any country, it faces its own set of challenges such as political instability, corruption, and poverty. Ultimately, whether Nigeria is seen as a great country is subjective and depends on individual perspectives and experiences.\"\n",
|
| 78 |
+
" },\n",
|
| 79 |
+
" \"finish_reason\": \"stop\"\n",
|
| 80 |
+
" }\n",
|
| 81 |
+
" ],\n",
|
| 82 |
+
" \"usage\": {\n",
|
| 83 |
+
" \"prompt_tokens\": 14,\n",
|
| 84 |
+
" \"completion_tokens\": 77,\n",
|
| 85 |
+
" \"total_tokens\": 91\n",
|
| 86 |
+
" }\n",
|
| 87 |
+
"}\n"
|
| 88 |
+
]
|
| 89 |
+
}
|
| 90 |
+
],
|
| 91 |
+
"source": [
|
| 92 |
+
"from pprint import pprint\n",
|
| 93 |
+
"\n",
|
| 94 |
+
"pprint(completion)"
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"cell_type": "code",
|
| 99 |
+
"execution_count": 13,
|
| 100 |
+
"metadata": {},
|
| 101 |
+
"outputs": [
|
| 102 |
+
{
|
| 103 |
+
"name": "stdout",
|
| 104 |
+
"output_type": "stream",
|
| 105 |
+
"text": [
|
| 106 |
+
"('As an AI language model, I do not have personal opinions. However, Nigeria '\n",
|
| 107 |
+
" 'has many great qualities such as rich cultural heritage, abundant natural '\n",
|
| 108 |
+
" 'resources, and diverse economy. However, like any country, it faces its own '\n",
|
| 109 |
+
" 'set of challenges such as political instability, corruption, and poverty. '\n",
|
| 110 |
+
" 'Ultimately, whether Nigeria is seen as a great country is subjective and '\n",
|
| 111 |
+
" 'depends on individual perspectives and experiences.')\n"
|
| 112 |
+
]
|
| 113 |
+
}
|
| 114 |
+
],
|
| 115 |
+
"source": [
|
| 116 |
+
"pprint(completion.choices[0].message.content)\n",
|
| 117 |
+
"# pprint(completion['choices'][0]['message']['content'])"
|
| 118 |
+
]
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"cell_type": "code",
|
| 122 |
+
"execution_count": 15,
|
| 123 |
+
"metadata": {},
|
| 124 |
+
"outputs": [
|
| 125 |
+
{
|
| 126 |
+
"name": "stdout",
|
| 127 |
+
"output_type": "stream",
|
| 128 |
+
"text": [
|
| 129 |
+
"Veronica\n"
|
| 130 |
+
]
|
| 131 |
+
}
|
| 132 |
+
],
|
| 133 |
+
"source": [
|
| 134 |
+
"message_history = []\n",
|
| 135 |
+
"\n",
|
| 136 |
+
"user_input = input(\"> \")\n",
|
| 137 |
+
"print(user_input)"
|
| 138 |
+
]
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"cell_type": "code",
|
| 142 |
+
"execution_count": 16,
|
| 143 |
+
"metadata": {},
|
| 144 |
+
"outputs": [],
|
| 145 |
+
"source": [
|
| 146 |
+
"message_history.append({\"role\": \"user\", \"content\": f\"{user_input}\"})"
|
| 147 |
+
]
|
| 148 |
+
},
|
| 149 |
+
{
|
| 150 |
+
"cell_type": "code",
|
| 151 |
+
"execution_count": 17,
|
| 152 |
+
"metadata": {},
|
| 153 |
+
"outputs": [
|
| 154 |
+
{
|
| 155 |
+
"name": "stdout",
|
| 156 |
+
"output_type": "stream",
|
| 157 |
+
"text": [
|
| 158 |
+
"Veronica is a name of Latin origin that means \"true image\" or \"image of God.\" It is a popular name for girls and has been used in many different cultures and countries. The name can be shortened to various nicknames, including Roni, Vero, and Nica. Some notable people with the name Veronica include actress Veronica Lake, singer Veronica Maggio, and Saint Veronica, a woman who according to Christian tradition wiped the face of Jesus as he carried the cross.\n"
|
| 159 |
+
]
|
| 160 |
+
}
|
| 161 |
+
],
|
| 162 |
+
"source": [
|
| 163 |
+
"completion = openai.ChatCompletion.create(\n",
|
| 164 |
+
" model=\"gpt-3.5-turbo\",\n",
|
| 165 |
+
" messages=message_history,\n",
|
| 166 |
+
")\n",
|
| 167 |
+
"\n",
|
| 168 |
+
"reply_content = completion.choices[0].message.content\n",
|
| 169 |
+
"print(reply_content)"
|
| 170 |
+
]
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"cell_type": "code",
|
| 174 |
+
"execution_count": 18,
|
| 175 |
+
"metadata": {},
|
| 176 |
+
"outputs": [
|
| 177 |
+
{
|
| 178 |
+
"name": "stdout",
|
| 179 |
+
"output_type": "stream",
|
| 180 |
+
"text": [
|
| 181 |
+
"('Veronica is a name of Latin origin that means \"true image\" or \"image of '\n",
|
| 182 |
+
" 'God.\" It is a popular name for girls and has been used in many different '\n",
|
| 183 |
+
" 'cultures and countries. The name can be shortened to various nicknames, '\n",
|
| 184 |
+
" 'including Roni, Vero, and Nica. Some notable people with the name Veronica '\n",
|
| 185 |
+
" 'include actress Veronica Lake, singer Veronica Maggio, and Saint Veronica, a '\n",
|
| 186 |
+
" 'woman who according to Christian tradition wiped the face of Jesus as he '\n",
|
| 187 |
+
" 'carried the cross.')\n"
|
| 188 |
+
]
|
| 189 |
+
}
|
| 190 |
+
],
|
| 191 |
+
"source": [
|
| 192 |
+
"pprint(reply_content)"
|
| 193 |
+
]
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"cell_type": "code",
|
| 197 |
+
"execution_count": 19,
|
| 198 |
+
"metadata": {},
|
| 199 |
+
"outputs": [],
|
| 200 |
+
"source": [
|
| 201 |
+
"message_history.append({\"role\": \"assistant\", \"content\": f\"{reply_content}\"})"
|
| 202 |
+
]
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"cell_type": "code",
|
| 206 |
+
"execution_count": 20,
|
| 207 |
+
"metadata": {},
|
| 208 |
+
"outputs": [
|
| 209 |
+
{
|
| 210 |
+
"name": "stdout",
|
| 211 |
+
"output_type": "stream",
|
| 212 |
+
"text": [
|
| 213 |
+
"User input was: Which other similar names\n",
|
| 214 |
+
"\n",
|
| 215 |
+
"\n",
|
| 216 |
+
"('Similar names to Veronica include:\\n'\n",
|
| 217 |
+
" '\\n'\n",
|
| 218 |
+
" '- Victoria\\n'\n",
|
| 219 |
+
" '- Vanessa\\n'\n",
|
| 220 |
+
" '- Valentina\\n'\n",
|
| 221 |
+
" '- Vivian\\n'\n",
|
| 222 |
+
" '- Verity\\n'\n",
|
| 223 |
+
" '- Verna\\n'\n",
|
| 224 |
+
" '- Vera\\n'\n",
|
| 225 |
+
" '- Vincentia\\n'\n",
|
| 226 |
+
" '- Vittoria\\n'\n",
|
| 227 |
+
" '- Venetia')\n"
|
| 228 |
+
]
|
| 229 |
+
}
|
| 230 |
+
],
|
| 231 |
+
"source": [
|
| 232 |
+
"user_input = input(\"> \")\n",
|
| 233 |
+
"print(f'User input was: {user_input}')\n",
|
| 234 |
+
"print('\\n')\n",
|
| 235 |
+
"\n",
|
| 236 |
+
"message_history.append({\"role\": \"user\", \"content\": f\"{user_input}\"})\n",
|
| 237 |
+
"\n",
|
| 238 |
+
"completion = openai.ChatCompletion.create(\n",
|
| 239 |
+
" model=\"gpt-3.5-turbo\",\n",
|
| 240 |
+
" messages=message_history,\n",
|
| 241 |
+
")\n",
|
| 242 |
+
"\n",
|
| 243 |
+
"reply_content = completion.choices[0].message.content\n",
|
| 244 |
+
"pprint(reply_content)\n"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"cell_type": "code",
|
| 249 |
+
"execution_count": 22,
|
| 250 |
+
"metadata": {},
|
| 251 |
+
"outputs": [
|
| 252 |
+
{
|
| 253 |
+
"name": "stdout",
|
| 254 |
+
"output_type": "stream",
|
| 255 |
+
"text": [
|
| 256 |
+
"User input was: Iphone or android?\n",
|
| 257 |
+
"\n",
|
| 258 |
+
"\n",
|
| 259 |
+
"(\"Sorry, as an AI language model, I don't have personal preferences. It \"\n",
|
| 260 |
+
" 'depends on your personal preference and needs. Both iPhone and Android have '\n",
|
| 261 |
+
" 'their own advantages and disadvantages. iPhone has a more streamlined and '\n",
|
| 262 |
+
" 'user-friendly interface, while Android offers more customization options and '\n",
|
| 263 |
+
" 'a wider range of models and prices. Both platforms are great for content '\n",
|
| 264 |
+
" 'creation, so it really comes down to your personal preference and budget.')\n",
|
| 265 |
+
"User input was: Samsung or Tecno\n",
|
| 266 |
+
"\n",
|
| 267 |
+
"\n",
|
| 268 |
+
"('In terms of quality and features, Samsung is generally known to be a better '\n",
|
| 269 |
+
" 'brand compared to Tecno. Samsung offers a wide range of options for '\n",
|
| 270 |
+
" 'different budgets and needs, from mid-range to high-end smartphones with '\n",
|
| 271 |
+
" 'advanced cameras, processors, and other features that are great for content '\n",
|
| 272 |
+
" 'creation. \\n'\n",
|
| 273 |
+
" '\\n'\n",
|
| 274 |
+
" 'While Tecno also offers affordable smartphones, they may not have as many '\n",
|
| 275 |
+
" 'premium features as Samsung, and their cameras may not be as advanced. '\n",
|
| 276 |
+
" 'However, Tecno can still be a good option if you are on a tight budget. '\n",
|
| 277 |
+
" 'Ultimately, the choice between Samsung and Tecno depends on your personal '\n",
|
| 278 |
+
" 'preferences and needs.')\n"
|
| 279 |
+
]
|
| 280 |
+
}
|
| 281 |
+
],
|
| 282 |
+
"source": [
|
| 283 |
+
"message_history = []\n",
|
| 284 |
+
"\n",
|
| 285 |
+
"def chat(user_input: str, system: str=None, role='user', model=\"gpt-3.5-turbo\"):\n",
|
| 286 |
+
" if system:\n",
|
| 287 |
+
" message_history.append({\"role\": 'system', \"content\": f\"{system}\"})\n",
|
| 288 |
+
" message_history.append({\"role\": role, \"content\": f\"{user_input}\"})\n",
|
| 289 |
+
"\n",
|
| 290 |
+
" completion = openai.ChatCompletion.create(\n",
|
| 291 |
+
" model=model,\n",
|
| 292 |
+
" messages=message_history,\n",
|
| 293 |
+
" )\n",
|
| 294 |
+
"\n",
|
| 295 |
+
" reply_content = completion.choices[0].message.content\n",
|
| 296 |
+
" message_history.append({\"role\": \"assistant\", \"content\": f\"{reply_content}\"})\n",
|
| 297 |
+
" return reply_content\n",
|
| 298 |
+
"\n",
|
| 299 |
+
"\n",
|
| 300 |
+
"for _ in range(2):\n",
|
| 301 |
+
" user_input = input('--> ')\n",
|
| 302 |
+
" print(f'User input was: {user_input}')\n",
|
| 303 |
+
" print('\\n')\n",
|
| 304 |
+
" \n",
|
| 305 |
+
" pprint(chat(user_input, system='You are a content creator on YouTube'))\n",
|
| 306 |
+
" print('\\n')"
|
| 307 |
+
]
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"cell_type": "code",
|
| 311 |
+
"execution_count": 28,
|
| 312 |
+
"metadata": {},
|
| 313 |
+
"outputs": [
|
| 314 |
+
{
|
| 315 |
+
"name": "stderr",
|
| 316 |
+
"output_type": "stream",
|
| 317 |
+
"text": [
|
| 318 |
+
"/home/alli/miniconda3/envs/openai/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 319 |
+
" from .autonotebook import tqdm as notebook_tqdm\n",
|
| 320 |
+
"/home/alli/miniconda3/envs/openai/lib/python3.11/site-packages/gradio/inputs.py:27: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
|
| 321 |
+
" warnings.warn(\n",
|
| 322 |
+
"/home/alli/miniconda3/envs/openai/lib/python3.11/site-packages/gradio/inputs.py:30: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 323 |
+
" super().__init__(\n",
|
| 324 |
+
"/home/alli/miniconda3/envs/openai/lib/python3.11/site-packages/gradio/inputs.py:30: UserWarning: `numeric` parameter is deprecated, and it has no effect\n",
|
| 325 |
+
" super().__init__(\n",
|
| 326 |
+
"/home/alli/miniconda3/envs/openai/lib/python3.11/site-packages/gradio/outputs.py:22: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
|
| 327 |
+
" warnings.warn(\n"
|
| 328 |
+
]
|
| 329 |
+
},
|
| 330 |
+
{
|
| 331 |
+
"name": "stdout",
|
| 332 |
+
"output_type": "stream",
|
| 333 |
+
"text": [
|
| 334 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 335 |
+
"\n",
|
| 336 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 337 |
+
]
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"data": {
|
| 341 |
+
"text/html": [
|
| 342 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 343 |
+
],
|
| 344 |
+
"text/plain": [
|
| 345 |
+
"<IPython.core.display.HTML object>"
|
| 346 |
+
]
|
| 347 |
+
},
|
| 348 |
+
"metadata": {},
|
| 349 |
+
"output_type": "display_data"
|
| 350 |
+
},
|
| 351 |
+
{
|
| 352 |
+
"data": {
|
| 353 |
+
"text/plain": []
|
| 354 |
+
},
|
| 355 |
+
"execution_count": 28,
|
| 356 |
+
"metadata": {},
|
| 357 |
+
"output_type": "execute_result"
|
| 358 |
+
}
|
| 359 |
+
],
|
| 360 |
+
"source": [
|
| 361 |
+
"import gradio as gr\n",
|
| 362 |
+
"\n",
|
| 363 |
+
"# Create the Gradio interface\n",
|
| 364 |
+
"iface = gr.Interface(\n",
|
| 365 |
+
" fn=chat,\n",
|
| 366 |
+
" inputs=gr.inputs.Textbox(placeholder=\"Enter your message...\"),\n",
|
| 367 |
+
" outputs=gr.outputs.Textbox()\n",
|
| 368 |
+
")\n",
|
| 369 |
+
"\n",
|
| 370 |
+
"# Start the interface\n",
|
| 371 |
+
"iface.launch()"
|
| 372 |
+
]
|
| 373 |
+
}
|
| 374 |
+
],
|
| 375 |
+
"metadata": {
|
| 376 |
+
"kernelspec": {
|
| 377 |
+
"display_name": "openai",
|
| 378 |
+
"language": "python",
|
| 379 |
+
"name": "python3"
|
| 380 |
+
},
|
| 381 |
+
"language_info": {
|
| 382 |
+
"codemirror_mode": {
|
| 383 |
+
"name": "ipython",
|
| 384 |
+
"version": 3
|
| 385 |
+
},
|
| 386 |
+
"file_extension": ".py",
|
| 387 |
+
"mimetype": "text/x-python",
|
| 388 |
+
"name": "python",
|
| 389 |
+
"nbconvert_exporter": "python",
|
| 390 |
+
"pygments_lexer": "ipython3",
|
| 391 |
+
"version": "3.11.4"
|
| 392 |
+
},
|
| 393 |
+
"orig_nbformat": 4
|
| 394 |
+
},
|
| 395 |
+
"nbformat": 4,
|
| 396 |
+
"nbformat_minor": 2
|
| 397 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.35.2
|
| 2 |
+
openai==0.27.8
|
| 3 |
+
python-dotenv==1.0.0
|
simple-app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
with gr.Blocks() as demo:
|
| 6 |
+
chatbot = gr.Chatbot()
|
| 7 |
+
msg = gr.Textbox()
|
| 8 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 9 |
+
|
| 10 |
+
def respond(message, chat_history):
|
| 11 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 12 |
+
chat_history.append((message, bot_message))
|
| 13 |
+
time.sleep(2)
|
| 14 |
+
return "", chat_history
|
| 15 |
+
|
| 16 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 17 |
+
|
| 18 |
+
demo.launch()
|
test.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def sentence_builder(quantity, animal, countries, place, activity_list, morning):
|
| 5 |
+
return f"""The {quantity} {animal}s from {" and ".join(countries)} went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
demo = gr.Interface(
|
| 9 |
+
sentence_builder,
|
| 10 |
+
[
|
| 11 |
+
gr.Slider(2, 20, value=4, label="Count", info="Choose between 2 and 20"),
|
| 12 |
+
gr.Dropdown(
|
| 13 |
+
["cat", "dog", "bird"], label="Animal", info="Will add more animals later!"
|
| 14 |
+
),
|
| 15 |
+
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries", info="Where are they from?"),
|
| 16 |
+
gr.Radio(["park", "zoo", "road"], label="Location", info="Where did they go?"),
|
| 17 |
+
gr.Dropdown(
|
| 18 |
+
["ran", "swam", "ate", "slept"], value=["swam", "slept"], multiselect=True, label="Activity", info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, eget aliquam nisl nunc vel nisl."
|
| 19 |
+
),
|
| 20 |
+
gr.Checkbox(label="Morning", info="Did they do it in the morning?"),
|
| 21 |
+
],
|
| 22 |
+
"text",
|
| 23 |
+
examples=[
|
| 24 |
+
[2, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"], True],
|
| 25 |
+
[4, "dog", ["Japan"], "zoo", ["ate", "swam"], False],
|
| 26 |
+
[10, "bird", ["USA", "Pakistan"], "road", ["ran"], False],
|
| 27 |
+
[8, "cat", ["Pakistan"], "zoo", ["ate"], True],
|
| 28 |
+
]
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
demo.launch()
|
work-app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from backend import generate_response, add_text, calc_cost
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# @click.command()
|
| 6 |
+
# @click.option(
|
| 7 |
+
# "-s",
|
| 8 |
+
# "--system_role",
|
| 9 |
+
# default="You are good assistant",
|
| 10 |
+
# type=str,
|
| 11 |
+
# help="Which role do you want the chatbot to take in replying your messages",
|
| 12 |
+
# )
|
| 13 |
+
# def app():
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
chatbot = gr.Chatbot()
|
| 16 |
+
|
| 17 |
+
with gr.Row():
|
| 18 |
+
with gr.Column(scale=0.9):
|
| 19 |
+
message = gr.Textbox(
|
| 20 |
+
show_label=False,
|
| 21 |
+
placeholder="Please enter a message and press Enter",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
with gr.Column(scale=0.1):
|
| 25 |
+
cost_view = gr.Number(label="Usage in $", value=0)
|
| 26 |
+
|
| 27 |
+
clear = gr.ClearButton([chatbot, message, cost_view])
|
| 28 |
+
models = gr.Radio(
|
| 29 |
+
value="gpt-3.5-turbo",
|
| 30 |
+
choices=["gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-16k"],
|
| 31 |
+
label="Models",
|
| 32 |
+
info="Which openai chat model to use",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
response = (
|
| 36 |
+
message.submit(add_text, [message, chatbot], [message, chatbot], queue=False)
|
| 37 |
+
.then(generate_response, [chatbot, models], chatbot)
|
| 38 |
+
.then(calc_cost, outputs=cost_view)
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
response.then(lambda: gr.update(interactive=True), None, [message], queue=False)
|
| 42 |
+
|
| 43 |
+
demo.queue()
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|