raphael825 commited on
Commit
60c2359
·
1 Parent(s): 3c69fe4

Change to test the json showing

Browse files
Files changed (1) hide show
  1. app.py +49 -4
app.py CHANGED
@@ -1,12 +1,57 @@
1
  import json
2
  import gradio as gr
 
 
 
 
 
 
 
3
 
4
 
5
- def greet(name):
6
- with open("book.json", "r") as read_file:
 
 
7
  test = json.load(read_file)
8
- return test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
- iface = gr.Interface(fn=greet, inputs=[], outputs='json')
12
  iface.launch()
 
1
  import json
2
  import gradio as gr
3
+ import Model
4
+ from pytube import YouTube
5
+ import whisper
6
+ import time
7
+ import pickle
8
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
9
+ from langchain.schema.document import Document
10
 
11
 
12
+ # # ==
13
+
14
+ def get_title(link):
15
+ with open("book.json", "r", encoding='utf-8') as read_file:
16
  test = json.load(read_file)
17
+ title = test[0]['item'][0]['title']
18
+ return link + title
19
+
20
+
21
+ def greet(link):
22
+ model_test = Model.get_title(link)
23
+ model_link = Model.greet(link)
24
+ result = model_test + model_link
25
+ return result
26
+
27
+
28
+ def youtube_text(link):
29
+ yt = YouTube(link)
30
+ yt.streams.filter(only_audio=True).first().download \
31
+ (output_path=".", filename="test.mp3")
32
+
33
+ start = time.time()
34
+ model = whisper.load_model("small")
35
+ result = model.transcribe("test.mp3")
36
+ end = time.time()
37
+
38
+ print(result["text"])
39
+ print(f"{end - start:.2f}sec")
40
+
41
+ text_splitter = RecursiveCharacterTextSplitter(
42
+ chunk_size=2000,
43
+ chunk_overlap=50,
44
+ length_function=len, )
45
+
46
+ docs = [Document(page_content=x) for x in text_splitter.split_text(result["text"])]
47
+
48
+ split_docs = text_splitter.split_documents(docs)
49
+
50
+ with open("split_example_small.pkl", "wb") as f:
51
+ pickle.dump(split_docs, f)
52
+
53
+ return docs[0]
54
 
55
 
56
+ iface = gr.Interface(fn=youtube_text, inputs='text', outputs='text')
57
  iface.launch()