deepakchawla-cb commited on
Commit
c868c44
·
1 Parent(s): 3609cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -1
app.py CHANGED
@@ -1,3 +1,91 @@
1
  import gradio as gr
 
 
2
 
3
- gr.load("models/fractalego/personal-speech-to-text-model").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
 
5
+ import os
6
+ from langchain.chat_models import ChatOpenAI
7
+ from langchain import ConversationChain, LLMChain, PromptTemplate
8
+ from langchain.memory import ConversationBufferWindowMemory
9
+ from flask_cors import CORS
10
+
11
+ from langchain.text_splitter import CharacterTextSplitter
12
+ from langchain.vectorstores import Chroma
13
+ from langchain.embeddings import OpenAIEmbeddings
14
+ from flask_cors import CORS, cross_origin
15
+
16
+ from langchain.chains import RetrievalQA
17
+ # from langchain.llms import OpenAI
18
+ # from langchain_community.chat_models import ChatOpenAI
19
+ from PyPDF2 import PdfReader
20
+ from typing_extensions import Concatenate
21
+ from langchain.chat_models import ChatOpenAI
22
+
23
+
24
+
25
+ from langchain.chat_models import ChatOpenAI
26
+ from langchain.prompts.chat import (
27
+ ChatPromptTemplate,
28
+ HumanMessagePromptTemplate,
29
+ SystemMessagePromptTemplate,
30
+ )
31
+ from langchain.schema import HumanMessage, SystemMessage
32
+
33
+ from flask import Flask, request, jsonify
34
+ import os
35
+
36
+
37
+
38
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
39
+
40
+ def predict():
41
+
42
+ customer_service_prompt = """
43
+ Create an email response based on the content of incoming emails. Your response should be tailored to the nature of the inquiry:
44
+
45
+ If the email mentions 'customer support,' reply with a message indicating that their request has been forwarded, and your team will respond within 48 hours. Include the support email address for further communication.
46
+
47
+ If the email indicates the customer is looking for new products, provide a response that shares a list of available products and directs them to your website for more information.
48
+
49
+ For payment-related inquiries, respond by informing the customer that your finance team will review their request and get back to them within the next 48 hours. Include the finance team's email address for any additional communication.
50
+
51
+ Ensure that the responses are clear, polite, and informative. Use appropriate language and tone for each scenario."
52
+ User's Query: {user_query}
53
+ Mail reply:
54
+ """
55
+
56
+ prompt = PromptTemplate(
57
+ input_variables=["user_query"],
58
+ template=customer_service_prompt)
59
+
60
+ inputs = {"input": ""}
61
+
62
+ chatgpt_llm = ChatOpenAI(model_name='gpt-3.5-turbo-16k', temperature=0,
63
+ openai_api_key=os.environ.get('OPENAI_API_KEY'))
64
+
65
+
66
+ chatgpt_chain = LLMChain(
67
+ llm=chatgpt_llm,
68
+ prompt=prompt)
69
+
70
+
71
+ def transcribe(audio):
72
+ sr, y = audio
73
+ y = y.astype(np.float32)
74
+ y /= np.max(np.abs(y))
75
+
76
+ results = predict(transcriber({"sampling_rate": sr, "raw": y})["text"])
77
+
78
+ return results
79
+
80
+
81
+
82
+
83
+ demo = gr.Interface(
84
+ transcribe,
85
+ gr.Audio(sources=["microphone"]),
86
+ "text",
87
+ )
88
+
89
+
90
+
91
+ demo.launch()