Spaces:
Build error
Build error
Commit ·
784eedc
1
Parent(s): ef74f9e
Added API call to hope space to generate story
Browse files- app.py +9 -1
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import re
|
|
| 11 |
from piper.voice import PiperVoice
|
| 12 |
import wave
|
| 13 |
from pydub import AudioSegment
|
|
|
|
| 14 |
|
| 15 |
logging.basicConfig(
|
| 16 |
level=logging.INFO,
|
|
@@ -19,6 +20,7 @@ logging.basicConfig(
|
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
app = FastAPI()
|
|
|
|
| 22 |
|
| 23 |
# Your WhatsApp verification token
|
| 24 |
VERIFY_TOKEN = os.getenv("WHATSAPP_VERIFY_TOKEN", "your_verification_token")
|
|
@@ -44,6 +46,10 @@ transcriber.model.config.forced_decoder_ids = transcriber.tokenizer.get_decoder_
|
|
| 44 |
|
| 45 |
amy_voice = PiperVoice.load("./piper/en_US-amy-medium.onnx")
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
@app.get("/webhook")
|
| 48 |
async def verify_webhook(request: Request):
|
| 49 |
"""
|
|
@@ -121,7 +127,9 @@ def backgnd_process_message(message):
|
|
| 121 |
elif message_type == "interactive":
|
| 122 |
if message["interactive"]["button_reply"]["id"] == "random_story":
|
| 123 |
ONGOING_CONVO[sender_id]['Story'] = "random_story"
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
elif message["interactive"]["button_reply"]["id"] == "own_story":
|
| 126 |
response_text = "Great!! Send me your story as the next message, it can be text or audio!!"
|
| 127 |
ONGOING_CONVO[sender_id]['Story'] = "PENDING"
|
|
|
|
| 11 |
from piper.voice import PiperVoice
|
| 12 |
import wave
|
| 13 |
from pydub import AudioSegment
|
| 14 |
+
from gradio_client import Client
|
| 15 |
|
| 16 |
logging.basicConfig(
|
| 17 |
level=logging.INFO,
|
|
|
|
| 20 |
logger = logging.getLogger(__name__)
|
| 21 |
|
| 22 |
app = FastAPI()
|
| 23 |
+
hope_client = Client("HopeLLM/HopeV1.0", hf_token=os.getenv("HF_READ_TKN"))
|
| 24 |
|
| 25 |
# Your WhatsApp verification token
|
| 26 |
VERIFY_TOKEN = os.getenv("WHATSAPP_VERIFY_TOKEN", "your_verification_token")
|
|
|
|
| 46 |
|
| 47 |
amy_voice = PiperVoice.load("./piper/en_US-amy-medium.onnx")
|
| 48 |
|
| 49 |
+
FIXED_PROMPT = "You are a helpful English Teaching Bot. You need to be friendly. Since you teach kids less than 7 years old, be motivating and don't point out any mistakes. Dont have long responses, keep your responses short. Assume I am your students and refer me as your student when replying"
|
| 50 |
+
#llama_input_def = f"<s> [INST] <<SYS>> {fixed_prompt} <</SYS>> Understand the story below and ask me one basic question regarding the story. Then wait for me to reply, when I reply, appreciate my participation and same way keep asking more questions one by one. Keep the questions one-liners and do not give much context. Keep everything brief \n {story_to_use} [/INST]"
|
| 51 |
+
llama_input_gen_random_story = f"<s> [INST] <<SYS>> {fixed_prompt} <</SYS>> Give me a random english story for grade 3 student. Don't make it very big, say 3 sentences. Just output the story and nothing else [/INST]"
|
| 52 |
+
|
| 53 |
@app.get("/webhook")
|
| 54 |
async def verify_webhook(request: Request):
|
| 55 |
"""
|
|
|
|
| 127 |
elif message_type == "interactive":
|
| 128 |
if message["interactive"]["button_reply"]["id"] == "random_story":
|
| 129 |
ONGOING_CONVO[sender_id]['Story'] = "random_story"
|
| 130 |
+
story_for_chat = hope_client.predict(input = llama_input_gen_random_story, api_name="/answer_question").split("[/INST]")
|
| 131 |
+
response_text = f"Perfect, I will choose a story for you!!, {story_for_chat}"
|
| 132 |
+
ONGOING_CONVO[sender_id]['Story'] = story_for_chat
|
| 133 |
elif message["interactive"]["button_reply"]["id"] == "own_story":
|
| 134 |
response_text = "Great!! Send me your story as the next message, it can be text or audio!!"
|
| 135 |
ONGOING_CONVO[sender_id]['Story'] = "PENDING"
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ torch
|
|
| 5 |
transformers
|
| 6 |
piper-tts
|
| 7 |
pydub
|
| 8 |
-
wave
|
|
|
|
|
|
| 5 |
transformers
|
| 6 |
piper-tts
|
| 7 |
pydub
|
| 8 |
+
wave
|
| 9 |
+
gradio_client
|