Spaces:
Runtime error
Runtime error
Commit
·
2eae17f
1
Parent(s):
f097af1
adding you tube processing LLM
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
| 3 |
import logging
|
| 4 |
from langchain.document_loaders import PDFMinerLoader,CSVLoader ,UnstructuredWordDocumentLoader,TextLoader,OnlinePDFLoader
|
|
@@ -70,6 +70,36 @@ def youtube_chat(youtube_link,API_key,llm='HuggingFace',temperature=0.1,max_toke
|
|
| 70 |
)
|
| 71 |
return "Youtube link Processing completed ..."
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
##################################################
|
| 74 |
##################################################
|
| 75 |
################### GRADIO #######################
|
|
@@ -139,4 +169,7 @@ with gr.Blocks(css="""#chatbot {font-size: 14px;min-height: 300px;}""") as demo:
|
|
| 139 |
load_youtube_bt.click(youtube_chat,inputs= [youtube_link,API_key,LLM_option,temperature,max_new_tokens,char_length],outputs=[langchain_status], queue=False)
|
| 140 |
clean_chat_btn.click(clear_chat, [], chatbot)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
| 142 |
demo.launch()
|
|
|
|
| 1 |
+
import time
|
| 2 |
import gradio as gr
|
| 3 |
import logging
|
| 4 |
from langchain.document_loaders import PDFMinerLoader,CSVLoader ,UnstructuredWordDocumentLoader,TextLoader,OnlinePDFLoader
|
|
|
|
| 70 |
)
|
| 71 |
return "Youtube link Processing completed ..."
|
| 72 |
|
| 73 |
+
def infer(question, history):
|
| 74 |
+
# res = []
|
| 75 |
+
# # for human, ai in history[:-1]:
|
| 76 |
+
# # pair = (human, ai)
|
| 77 |
+
# # res.append(pair)
|
| 78 |
+
|
| 79 |
+
# chat_history = res
|
| 80 |
+
print("Question in infer :",question)
|
| 81 |
+
result = qa({"query": question})
|
| 82 |
+
matching_docs_score = vector_db.similarity_search_with_score(question)
|
| 83 |
+
|
| 84 |
+
print(" Matching_doc ",matching_docs_score)
|
| 85 |
+
|
| 86 |
+
return result["result"]
|
| 87 |
+
|
| 88 |
+
def bot(history):
|
| 89 |
+
|
| 90 |
+
response = infer(history[-1][0], history)
|
| 91 |
+
history[-1][1] = ""
|
| 92 |
+
|
| 93 |
+
for character in response:
|
| 94 |
+
history[-1][1] += character
|
| 95 |
+
time.sleep(0.05)
|
| 96 |
+
yield history
|
| 97 |
+
|
| 98 |
+
def add_text(history, text):
|
| 99 |
+
history = history + [(text, None)]
|
| 100 |
+
return history, ""
|
| 101 |
+
|
| 102 |
+
|
| 103 |
##################################################
|
| 104 |
##################################################
|
| 105 |
################### GRADIO #######################
|
|
|
|
| 169 |
load_youtube_bt.click(youtube_chat,inputs= [youtube_link,API_key,LLM_option,temperature,max_new_tokens,char_length],outputs=[langchain_status], queue=False)
|
| 170 |
clean_chat_btn.click(clear_chat, [], chatbot)
|
| 171 |
|
| 172 |
+
question.submit(add_text, inputs=[chatbot, question], outputs=[chatbot, question]).then(bot, chatbot, chatbot)
|
| 173 |
+
submit_btn.click(add_text, inputs=[chatbot, question], outputs=[chatbot, question]).then(bot, chatbot, chatbot)
|
| 174 |
+
|
| 175 |
demo.launch()
|