Spaces:
Sleeping
Sleeping
ShivaPrakash
commited on
Commit
•
087d834
1
Parent(s):
4aa7caf
Upload 2 files
Browse files- app.py +60 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[5]:
|
5 |
+
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
import anthropic
|
9 |
+
import base64
|
10 |
+
import httpx
|
11 |
+
import os
|
12 |
+
import time
|
13 |
+
import random
|
14 |
+
import requests
|
15 |
+
|
16 |
+
|
17 |
+
# In[8]:
|
18 |
+
|
19 |
+
|
20 |
+
import gradio as gr
|
21 |
+
import base64
|
22 |
+
import requests
|
23 |
+
import time
|
24 |
+
|
25 |
+
def print_like_dislike(x: gr.LikeData):
|
26 |
+
print(x.index, x.value, x.liked)
|
27 |
+
|
28 |
+
def add_message(history, message):
|
29 |
+
# Since we're now using gr.Textbox, we only handle text inputs
|
30 |
+
if message is not None:
|
31 |
+
prompt = message
|
32 |
+
response = random.choice(["Noted. Will check that and get back", "Okay. Interesting!!","Hmm! Can you give me more info on this"]
|
33 |
+
response = (response.json())['response']
|
34 |
+
history.append((message, response))
|
35 |
+
return history, gr.Textbox(value=None, interactive=False)
|
36 |
+
|
37 |
+
def bot(history):
|
38 |
+
for character in history[-1][1]:
|
39 |
+
history[-1][1] += character
|
40 |
+
time.sleep(0.05)
|
41 |
+
yield history
|
42 |
+
|
43 |
+
with gr.Blocks() as demo:
|
44 |
+
chatbot = gr.Chatbot(
|
45 |
+
[],
|
46 |
+
elem_id="chatbot",
|
47 |
+
bubble_full_width=False,
|
48 |
+
)
|
49 |
+
|
50 |
+
# Use gr.Textbox for chat input
|
51 |
+
chat_input = gr.Textbox(placeholder="Enter message ...", show_label=True)
|
52 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
53 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
54 |
+
bot_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input])
|
55 |
+
|
56 |
+
chatbot.like(print_like_dislike, None, None)
|
57 |
+
|
58 |
+
demo.queue()
|
59 |
+
demo.launch()
|
60 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
anthropic
|
2 |
+
gradio
|
3 |
+
|
4 |
+
|
5 |
+
|